File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert timestamp to date

 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I convert a java.sql.Timestamp to java.sql.Date? I thought I could just cast the (java.sql.Date)timestamp_var but that does nto work.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both of the classes (java.sql.Date and java.sql.Timestamp) subclass java.util.Date, so as "siblings" you can not cast instances of one to instances of another. However you'll notice that both of them inherit [or override] the "getTime()" method which returns a value of type "long". Both of them also have a constructor that takes a value of type "long".
So you can do the following:
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the JDBC forum...
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic