0

I have the following strings which are coming from external server -

"2015-02-25T04:23:34.874-08:00", "2015-02-25T12:22:49.275Z"

I have to show these strings in my site along with the time zone which is available in the above strings.

Following is the format to show the date in my site -

"Feb 25, 2015 03:23 AM, GMT-08:00", "Feb 25, 2015 12:22 AM, GMT"

In JAVA 7 we have new pattern character 'X' to resolve this. We can parse both these values using the single pattern

"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"

But I am stuck with JAVA 6. What is the right pattern to use for JAVA 6 ?

Awesome
  • 5,689
  • 8
  • 33
  • 58

3 Answers3

0

The incoming date does not depict the timezone, still if you are sure that you would be getting all times in GMT, then you can simply format the incoming date using SimpleDateFormat and get you desired format.

Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57
  • Incoming date has time zone details as well. Observe the first value which has 08:00 at the end which denotes the timezone GMT-08:00. – Awesome Mar 23 '15 at 06:45
0
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
dateFormat.format("2015-02-25T04:23:34.874-08:00")

The format is customizable.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
Rohith K
  • 1,433
  • 10
  • 15
0

You have an XSD dateTime on your hands which is notoriously hard to parse using standard java (this might have changed in java 8?)

The timezone is not compatible with the SimpleDateFormat parser nor is the random number of milliseconds (can be more than 3 per the spec).

I have not used it but I'm pretty sure Joda time has an easy solution for this. In case you're interested, here is some custom code I wrote a long time ago that parses them as well: https://github.com/nablex/types-base/blob/master/src/main/java/be/nabu/libs/types/utils/TimeFormat.java

nablex
  • 4,635
  • 4
  • 36
  • 51