aspose file tools*
The moose likes JDBC and the fly likes How to manipulate the Date object in yyyy-MM-DD HH:MM:SS format. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to manipulate the Date object in yyyy-MM-DD HH:MM:SS format." Watch "How to manipulate the Date object in yyyy-MM-DD HH:MM:SS format." New topic
Author

How to manipulate the Date object in yyyy-MM-DD HH:MM:SS format.

Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
Hi,
I am retreiving the date in the ResultSet using ResultSet.getDate("Column_name"), which returns the java.sql.java object. When I print this object, it prints the date in YYYY-MM-DD like 2003-11-14. But I need this value in yyyy-MM-DD HH:MM:SS AM/PM like 10/17/2008 4:43:25 PM. Please can you help me how can I do this.

Rajesh Kumar Raj
Greenhorn

Joined: Sep 03, 2007
Posts: 11

Try resultSet.getTimeStamp() method to fetch the Date.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2500
    
    8

Attention. In your original post, your format yyyy-MM-DD HH:MM:SS AM/PM does not match what you want: 10/17/2008 4:43:25 PM. The format starts with year, your example starts with month.



You can format your date with java.text.SimpleDateFormat.


OCUP UML fundamental and ITIL foundation
youtube channel
W Pearce
Ranch Hand

Joined: Jan 06, 2009
Posts: 32


SCJP 6, SCWCD 5
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Or maybe, you can use java.util.Calendar and java.util.GregorianCalendar..

Hope this help.


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
Thank you!!. It worked with getTimstamp() and SimpleDateFormat.

Thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to manipulate the Date object in yyyy-MM-DD HH:MM:SS format.