• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xsd datetime format

 
Ruth Marx
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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()) );
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Shanty
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your valuable reply to this post.
It was a great help to me as well.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

It shows how useful a year-old post can be
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Shanti",

Please read your private messages regarding an important announcement.

Thank you,

Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic