Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Dates: Part 2

 
Scott Carter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain the proper way to convert from a java.sql.Date to java.util.Date? This is the opposite of the question I asked earlier......
 
Michael Hildner
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.Date extends java.util.Date (check out the API on this). So on either type of Date, you can use setTime and getTime. If you want to create a new java.util.Date from a java.sql.Date use:
assumming sqlDate is a java.sql.Date Object:
java.util.Date utilDate = new java.util.Date(sqlDate.getTime())
if the java.util.Date already exists and you just want to set the time:
utilDate.setTime(sqlDate.getTime());
Hope this helps.
Michael
[This message has been edited by Michael Hildner (edited February 04, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic