aspose file tools*
The moose likes Beginning Java and the fly likes xsd datetime format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "xsd datetime format" Watch "xsd datetime format" New topic
Author

xsd datetime format

Ruth Marx
Greenhorn

Joined: Jul 12, 2007
Posts: 11
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

Joined: Oct 27, 2005
Posts: 19696
    
  20


Please keep in mind that the second row can throw a ParseException if you get a string in the wrong format.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ruth Marx
Greenhorn

Joined: Jul 12, 2007
Posts: 11
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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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

Joined: Sep 19, 2008
Posts: 1
Thanks a lot for your valuable reply to this post.
It was a great help to me as well.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Welcome to JavaRanch

It shows how useful a year-old post can be
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

"Shanti",

Please read your private messages regarding an important announcement.

Thank you,

Rob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xsd datetime format