8

Is there a way to convert java.sql.Date to java.sql.Timestamp?

I have the following code:

java.sql.Date = new Date();
java.sql.Timestamp timestamp = new java.sql.Timestamp(date);

But the Timestamp constructor doesn't seem to support that variable type.

3
  • 1
    Should not it be java.sql.Date date = new Date();? Is it a typo or are you missing variable name? Commented Jan 12, 2016 at 14:58
  • u can fetch time in milliseconds and then get it converted in my opinion Commented Jan 12, 2016 at 15:00
  • 2
    stackoverflow.com/questions/22856931/… Commented Jan 12, 2016 at 15:05

1 Answer 1

18

You can get the constructor that takes milliseconds as argument, like:

java.sql.Date date = new Date();
java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.