Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Reshma Rangarajan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21133
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Pie
Posts: 49408
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can use the %T?? tags in Formatter#format, PrintStream#printf, etc. For details, look in the documentation for java.util.Formatter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic