Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ANOTHER java.sql.date PROBLEM!!!

Status
Not open for further replies.

eh171

Programmer
Joined
Feb 21, 2003
Messages
9
Location
GB
Hi. I am trying to get a date object in the form 2003/02/01 14:45:23. newbob your code just gets me the date. How would I also get the time????
 
Hi eh171 - don't know if this is any help as background info.

SQL date datatype includes time as default - convert it to a string using a format such as 'HH24:MI:SS' (eg. using TO_CHAR() or similar) to see the time.

If you are retrieving a string, you may be missing the (optional) date.

Just a thought.

If I'm completely on the wrong track, can you give an extract of you code ?
 
Here is an example that should give you what you want. You should use the time zone for your location. I believe that the Date class has been deprecated....but it should still compile.
..........................................................

TimeZone tz = null;
Date now = null;
SimpleDateFormat sdf = null;
String timestamp = null;

tz = TimeZone.getTimeZone("EST");
now = new Date();
sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
sdf.setTimeZone(tz);
timestamp = sdf.format(now);

..........................................................
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top