I need to convert a date from one format to another in java. Here I am not converting the date from one format to another format. First I have to retrieve from XMLGregorianCalendar and then I have to convert it to yyyyDDDHHmmssSSS which should be same as the below explained by hard coding.
Problem:
I have hard code a value in string and then I try to convert to date and then to back to original value(yyyyDDDHHmmssSSS) format, I am getting the expected value as below.
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyDDDHHmmssSSS");
String t ="20160690600530";
Date dateq = sdf1.parse(t);
System.out.println("After converting"+ dateq );
System.out.println("normalTest--->"+sdf1.format(dateq));
Output: (Expected one)
Wed Mar 09 06:00:53 EST 2016
sss-->2016069010053000
Same way I am trying to convert a value from the XMLGregorianCalendar to yyyyDDDHHmmssSSS, but I am getting a different value from the above.
Pojo ddd = new Pojo();
XMLGregorianCalendar gregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar("2016-03-09T06:00:53.0Z");
ddd.setMemberEffectiveTimestamp(gregorianCalendar);
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyDDDHHmmssSSS");
Date date1 = ddd.getMemberEffectiveTimestamp().toGregorianCalendar().getTime();
System.out.println("date1--->"+date1);
System.out.println("sss-->"+ sdf1.format(date1));
Output:
date1--->Wed Mar 09 01:00:53 EST 2016
sss-->2016069010053000
I need the "2016-03-09T06:00:53.0Z" to convert to 2016069010053000 value. I am not sure how to achieve it.