0

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.

4

2 回答 2

3

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().

于 2012-07-07T17:12:28.073 回答
1

只需使用:

java.sql.Timestamp timeStamp = new java.sql.Timestamp(new java.util.Date().getTime());

参考: 时间戳

于 2012-07-07T17:16:14.240 回答