Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

xsd datetime format

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm using a javascript popup calendar on a web page which can return a timestamp in either of 3 formats (i can choose whichever):

dd-mm-yyyy hh:mm:ss
mm/dd/yyyy hh:mm:ss
yyyy-mm-dd hh:mm:ss

I want to convert this form value into the xsd datetime format yyyy-MM-ddThh:mm:ss.

How can I do this?

I have been using the following code, but this just deals with today's date. I need to alter it so that it can deal with the value from the popup calendar:

Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
StringBuffer sb = new StringBuffer( sdf.format(calendar.getTime()) );
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please keep in mind that the second row can throw a ParseException if you get a string in the wrong format.
 
Ruth Marx
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob, I am aware of that. That's why I'm wondering is there a way to convert the string value into some java calendar instance which can then be parsed?

Regards,

Ruth
 
Rob Spoor
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there is no direct way of parsing Calendar objects. Instead, you parse Date objects.

When you called calendar.getTime(), that returned a Date object. I basically did the same except without using a Calendar object, which is unnecessary for what you want.

If you do want a Calendar object, create one with Calendar.getInstance(), then use setTime() to set the Date object you got from parsing.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your valuable reply to this post.
It was a great help to me as well.
 
Marshal
Posts: 79633
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

It shows how useful a year-old post can be
 
Rob Spoor
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Shanti",

Please read your private messages regarding an important announcement.

Thank you,

Rob
reply
    Bookmark Topic Watch Topic
  • New Topic