1

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!!

Xiabili
  • 486
  • 5
  • 20

2 Answers2

5

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)
Behrang
  • 46,888
  • 25
  • 118
  • 160
0

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.

Dilum Ranatunga
  • 13,254
  • 3
  • 41
  • 52