0

ebay api retruns the timestamp as <Timestamp>2014-11-13T06:31:38.258Z</Timestamp> which has to be parsed to java.util.Date, I could come with the following yyyy-MM-dd'T'HH:mm:ss.sssZ but th result of which is the timezone 2014-11-13T02:03:23.023-0500 trying to format in result freemarker with the below line of code

<#assign readddate = 
objectConstructor("java.text.SimpleDateFormat","yyyy-MM-dd'T'HH:mm:ss.sssZ")>

results in

[12:41:03 PM] Somasundaram: Caused by: java.text.ParseException: 
Unparseable date: "2014-11-11T05:28:45.000Z"
Somasundaram Sekar
  • 5,244
  • 6
  • 43
  • 85
  • 1
    I've answered the question as best I can, but there seems to be a mixture of formatting and parsing in your question, which isn't terribly clear. (It's not clear what you mean by "I could come with the following" either.) It would be helpful if you'd go over your question again and try to make it clearer - not just to get you more help now, but to help future readers too. – Jon Skeet Nov 13 '14 at 07:24
  • possible duplicate of [Converting ISO 8601-compliant String to java.util.Date](http://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date) – Basil Bourque Nov 13 '14 at 09:19

1 Answers1

1

You should change the time zone specifier part of the pattern to X, which is the ISO-8601 time zone (well, UTC offset) specifier:

objectConstructor("java.text.SimpleDateFormat","yyyy-MM-dd'T'HH:mm:ss.sssX")

That will handle Z and treat it as UTC correctly.

Note that this was introduced in Java 7 - if you're using Java 6 or earlier, you'll need a different solution. (Let me know; hopefully this won't be a problem for you.)

Your comment about "the result of which is the time zone 2014-11-13T02:03:23.023-0500" suggests that you may not realize that a java.util.Date doesn't have a time zone. If something is converting it into a UTC-5 time, then it's probably applying the local time zone - if you're formatting a value, or parsing text that doesn't include a UTC offset, you should specify the time zone in the SimpleDateFormat.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194