• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Datetime datatype

 
Vivek Alampally
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am reading a Datetime datatype column from SQL server table. For some reason it is not printing hours, minutes seconds. How can I make my program to print hours, minutes seconds also.

Date s = resultset.getDate("last_modified_time"); // where last_modified_time is name of Datetime datatype column
System.out.println(s);

Thanks
Vivek
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, if you want to change the way a date is displayed, you can use java.text.DateFormat. But I looked at the documentation for java.sql.Date. It says:
To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
I take this to mean that even if you use DateFormat, it will not provide the time value as you'd expect. Try using java.sql.Timestamp instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic