| Author |
Generate date in 2011-04-26T16:52:57-05:00 format.
|
Reshma Rangarajan
Greenhorn
Joined: Nov 02, 2010
Posts: 8
|
|
Hi,
I am supposed to generate the current date in the below format and then set it onto an XML before consuming a web service.
2011-04-26T16:52:57-05:00
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,
Reshma
|
 |
N Sahni
Ranch Hand
Joined: Jul 07, 2011
Posts: 55
|
|
Hi,
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 | nsahni@infocepts.com | www.infocepts.com
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32644
|
|
|
Or you can use the %T?? tags in Formatter#format, PrintStream#printf, etc. For details, look in the documentation for java.util.Formatter.
|
 |
 |
|
|
subject: Generate date in 2011-04-26T16:52:57-05:00 format.
|
|
|