Convert Hippo JCR datetime to Java format
Question
I use JCR Query to get some news from Hippo repository. and as result I getting date in this format:
2011-04-07T08:34:13.093Z
can someone tell me how can I convert it to like this:
07-04-2011 08:34
in a simple way.
Thanks!!
Solution
You can do this using SimpleDateFormat
:
ParsePosition pp = new ParsePosition(0);
SimpleDateFormat hippoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date javaDate = hippoFormat.parse("2011-04-07T08:34:13.093Z", pp)
OTHER TIPS
The input string you've described is formatted is an XSD dateTime. You can use SimpleDateFormat to convert to a java.util.Date or java.util.Calendar, but you need to decide what to do with timezone, etc. The 'Z' at the end of the input string means it is 'Zulu' time -- i.e. UTC. When you convert, do you want the time in UTC or local timezone? If the input strings can also be non-UTC, you will need to code some additional logic.
Consider getting the source for Jena framework's XSDDateTime class.