• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Amit K Jain
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try resultSet.getTimeStamp() method to fetch the Date.
 
Jan Cumps
Bartender
Posts: 2602
13
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
W Pearce
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or maybe, you can use java.util.Calendar and java.util.GregorianCalendar..

Hope this help.
 
Amit K Jain
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!!. It worked with getTimstamp() and SimpleDateFormat.

Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic