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
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply 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: 2344

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
ITIL foundation
W Pearce
Ranch Hand

Joined: Jan 06, 2009
Posts: 32


SCJP 6, SCWCD 5
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 482
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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to manipulate the Date object in yyyy-MM-DD HH:MM:SS format.
 
Similar Threads
Getting date as a string from util.date object in desired format format
Convert the String to date format
xsd datetime format
how to change the date,Time format after accessing it from the database
Number of days from today