File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes simpledateformat problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "simpledateformat problem" Watch "simpledateformat problem" New topic
Author

simpledateformat problem

John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 171


I am having a problem formatting the above code

i need the date to look like this:
2009-05-22T00:16:51-04:00

But it comes out like this:
2009-05-22T00:16:51-0400

Is there a pattern in SDF to include the colon?

thanks
john
Birla Murugesan
Ranch Hand

Joined: Nov 25, 2008
Posts: 66
Jhon,

There is no pattern available for output which you needed.

In your code :SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

the capital Z denotes,for formatting you have been used RFC 822 time zone format.

so if go for the Pacific Standard Time ie use small letter 'z' instead of capital

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");

you can get the output like this 2009-05-22T00:16:51GMT04:00

which is moreover what you expected.

Birla

John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 171
Birla Murugesan wrote:Jhon,

There is no pattern available for output which you needed.

In your code :SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

the capital Z denotes,for formatting you have been used RFC 822 time zone format.

so if go for the Pacific Standard Time ie use small letter 'z' instead of capital

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");

you can get the output like this 2009-05-22T00:16:51GMT04:00

which is moreover what you expected.

Birla




Unfortunately i need this exact date format 2009-05-22T00:16:51-04:00
amazon only accepts that format.
So i would have to manually add the colon?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: simpledateformat problem
 
Similar Threads
Problem in parsing String into a particular Date format
dates and JDBC
Problem in Coverting one Date Format to Other date Format
HELP needed on DATE
Problem using Calendar class