• 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).]
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!