1

I'm trying to extract the following DateTime from an XML using a middleware called Oracle BAM, but that doesn't matter. I'm getting the following output on the log:

Invalid DateTime specified: 2016-07-21T11:25:00.000+01:00
java.text.ParseException: Unparseable date: "2016-07-21T11:25:00.000+01:00"
     at java.text.DateFormat.parse(DateFormat.java:366)
     ...

I've read the documentation and the format is exactly like they want. What am I missing?

Elsendion
  • 187
  • 1
  • 4
  • 15
  • `DateFormat.setLenient(true)`? As comment you seem to suggest that milliseconds .000 is not in your format. – Joop Eggen Jul 21 '16 at 12:13

2 Answers2

0

You can try this to simple date format valdation

 public Date validateDateFormat(String dateToValdate) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HHmmss");
//To make strict date format validation
formatter.setLenient(false);
Date parsedDate = null;
try {
    parsedDate = formatter.parse(dateToValdate);
    System.out.println("++validated DATE TIME ++"+formatter.format(parsedDate));

} catch (ParseException e) {
    //Handle exception
}
return parsedDate;}
0

You can simple parse that date as shown below.

package com.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Sample {
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
        System.out.println(sdf.parse("2016-07-21T11:25:00.000+01:00"));
    }
}
Naveen
  • 830
  • 9
  • 19