My table, chat_users
, contains an attribute last_activity
that is a Timestamp
.
What is the Java code to write that value?
I tried Timestamp last_activity ;
but i don't know how to pass parameter to it.
My table, chat_users
, contains an attribute last_activity
that is a Timestamp
.
What is the Java code to write that value?
I tried Timestamp last_activity ;
but i don't know how to pass parameter to it.
In order to use Timestamp
, you could use it like this:
Date dateObject = new Date(); // your date object
new Timestamp(dateObject.getTime());
Another possibility, depending on how you are implementing it: System.currentTimeMillis()
.
Basically System.currentTimeMillis()
returns the number of milliseconds since January 1, 1970, 00:00:00 GMT until current time. The same thing does Date.getTime()
.
只需使用:
java.sql.Timestamp timeStamp = new java.sql.Timestamp(new java.util.Date().getTime());
参考: 时间戳