• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert a java.util.Date object to java.sql.Timestamp Object?  RSS feed

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this seems to be a silly move, but I need
to import some sales data captures from pos,
so that the timestamp is converted to java.util.Date by POI,
now in my CRM, I need to keep them as Timestamps,
How do I convert a java.util.Date object to a java.sql.Timestamp object?
Thanks in advance
Jack
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date has a getTime method which gives you a long value that you can use to create a Timestamp
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk wrote:How do I convert a java.util.Date object to a java.sql.Timestamp object?

E Armitage already told you, but the only thing I'd add is: don't do anything else.

Timestamps in Java (and actually in your database too) are values, so they're the same the world over. If you start getting clever, and trying to "adjust" them for different timezones and/or DST, you will almost certainly screw things up.

For more information, read the ABriefHistoryOfJavaTime page.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!