Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert java.util.Date into current time in timestamp..?

Tags:

java

sql

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.

like image 549
codeofnode Avatar asked Oct 19 '12 08:10

codeofnode


People also ask

Does Java Util date have timestamp?

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.

Is Java Util date UTC?

java. util. Date has no specific time zone, although its value is most commonly thought of in relation to UTC.


1 Answers

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())
like image 150
Grisha Weintraub Avatar answered Sep 28 '22 13:09

Grisha Weintraub