This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to convert Timestampformat to another format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert Timestampformat to another format" Watch "How to convert Timestampformat to another format" New topic

How to convert Timestampformat to another format

kiranb reddy

Joined: Sep 28, 2008
Posts: 20
Dear All,

I have a requirement to format the Timestamp format to another format, could any one explain the steps to do it.

The default timestamp format is yyyy-MM-dd HH:MM:SS

I need to fomrat it to dd-MM-yyyy HH:MM:SS

Please help to do this, and the return type must be always java.sql.TimeStamp.

Thanks in Advance.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

java.sql.TimeStamp does not hold any particular format. It just holds the date itself (the values).
If you want to format dates, you can have a look at java.text.SimpleDateFormat.

[My Blog]
All roads lead to JavaRanch
Rob Spoor

Joined: Oct 27, 2005
Posts: 19556

Christophe is correct. The only way to get hold of a date in a particular format is to use a String for the format.

How To Ask Questions How To Answer Questions
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to convert Timestampformat to another format
Similar Threads
How to fetch Date Field from excel sheet in Java
Bug in java.util.Date.toString():?
xsd datetime format
Insert a row into MS Access2003 successfully,But the long date(YYYY/MM/DD HH:mm:ss) was changed
How do I pad a timestamp string with 0s?