This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
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: 18541
    
    8

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
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.
 
Similar Threads
Time Difference
convert now timestamp to 2011-05-02T19:50:42.868-04:00
How to change Date Format
Time Difference
Convert String to Date format