File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Generate date in 2011-04-26T16:52:57-05:00 format. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generate date in 2011-04-26T16:52:57-05:00 format." Watch "Generate date in 2011-04-26T16:52:57-05:00 format." New topic

Generate date in 2011-04-26T16:52:57-05:00 format.

Reshma Rangarajan

Joined: Nov 02, 2010
Posts: 8

I am supposed to generate the current date in the below format and then set it onto an XML before consuming a web service.

By Using this code snippet below am able to generate the date without the 'T' and offset information.

SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss-05.00");
Date now = new Date();
String strDate = sdfDate.format(now);

I was able to get an output as 2011-08-25 02:22:10-05.00

Can someone please let me know how to get the 'T' between the Date and Timestamp.

Thanks in Advance,
N Sahni
Ranch Hand

Joined: Jul 07, 2011
Posts: 55


This means that your XML schema for that particular element is of type dataTime.

One option I would suggest is having compiled java classes of that XML schema. With this you can directly set that element using Calendar.getInstance();
It'll automatically reflect in this format.

Thanks and Regards,
Nilesh Sahni | |
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
Or you can use the %T?? tags in Formatter#format, PrintStream#printf, etc. For details, look in the documentation for java.util.Formatter.
I agree. Here's the link:
subject: Generate date in 2011-04-26T16:52:57-05:00 format.
It's not a secret anymore!