How can I create a Timestamp with the date 23/09/2007?
Java SQL Timestamp setTime() function with examples The function is used to set the time of the Timestamp object. The function takes time in milliseconds which represents the time in milliseconds after 1st January, 1970. Syntax: ts1.
You can use Instant#ofEpochSecond to get an Instant out of the given timestamp and then use LocalDate. ofInstant to get a LocalDate out of the obtained Instant . Learn more about the modern Date-Time API from Trail: Date Time.
By Timestamp
, I presume you mean java.sql.Timestamp
. You will notice that this class has a constructor that accepts a long
argument. You can parse this using the DateFormat
class:
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Date date = dateFormat.parse("23/09/2007"); long time = date.getTime(); new Timestamp(time);
What about this?
java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf("2007-09-23 10:10:10.0");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With