• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsd:DateTime to timestamp in java

 
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, can anyone suggest me to resolve the problem i am stuck with.Below is the code snippet which is g
iving me parseException .

value coming from xml is <CreatedTS>2006-05-04T18:13:51.0Z</CreatedTS

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
java.util.Date parsedDate = dateFormat.parse(e.getChild("CreatedTS",doc.getRootElement().getNamespace()).getValue());
java.sql.Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());
dataSyncBean.setCreatedTs(timestamp);

Thanks-Arun>
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
exceprion which i am getting is

java.text.ParseException: Unparseable date: "2006-05-04T18:13:51.0Z"
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your format string is wrong. Note that "hh" means 12-hour clock. You most likely want "HH", 24-hour clock. Also, you should use "X" instead of "Z" for ISO-8601 timezones. (Note that "X" will only work if you are using Java 7 or newer). So your format string should look like this:

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

An alternative way to parse ISO-8601 format dates and times (which is the standard format that is used in XML for dates and times) is this:
 
arunseege paramashivappa
Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jesper .It worked .
 
I don't always make ads but when I do they're tiny
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic