Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
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.

 
Greenhorn
Posts: 11
Android MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try resultSet.getTimeStamp() method to fetch the Date.
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • 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.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • 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.
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic