i am making a program in java. i am using the following code
u.setLastlogin(new java.util.Date());
above function accepts parameter as java.util.Date
but i want to store this value in a database table where the column is of type timestamp
?
can any one help how to code so that i can insert the current timestamp of the system in the table. thanks.
util. Date that allows the JDBC API to identify this as an SQL TIMESTAMP value. It adds the ability to hold the SQL TIMESTAMP fractional seconds value, by allowing the specification of fractional seconds to a precision of nanoseconds.
java. util. Date has no specific time zone, although its value is most commonly thought of in relation to UTC.
You can convert Date
to Timestamp
as follows:
Timestamp timestamp = new Timestamp(date.getTime());
And if you want timestamp of current date:
new Timestamp(System.currentTimeMillis())
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