Win a copy of Svelte and Sapper in Action this week in the JavaScript 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic