简体   繁体   中英

converting XML gregorian calender to Date and string and vice versa

Many people might have tried to play with this....

I found a solution..thought it will be helpful to some one around.

XMLGregorianCalendar xmlGre=DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());

System.out.println(xmlGre.getXMLSchemaType());
Calendar cal=DatatypeConverter.parseDate(xmlGre.toXMLFormat());         
System.out.println(cal.getTime().toString());

2002-12-16T16:20:10+04:00 is one type of date

2013-12-03T16:41:52.399-05:00 is another type of date it can convert.

The catch here is the time Zone. Simple date format can not convert the timezone if there is a colon inside it.

{ http://www.w3.org/2001/XMLSchema }dateTime is the xml element it is using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM