java get timestamp_Java Timestamp.getTime方法代码示例
时间: 2024-01-19 15:02:40 浏览: 131
Sure! Here is a code example of getting the timestamp in Java using the `Timestamp.getTime()` method:
```
import java.sql.Timestamp;
public class TimestampExample {
public static void main(String[] args) {
// Create a new Timestamp object
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
// Get the timestamp value as a long
long ts = timestamp.getTime();
// Print the timestamp value
System.out.println("Timestamp value in milliseconds: " + ts);
}
}
```
In this example, we first create a new `Timestamp` object using the current system time. We then call the `getTime()` method on the `Timestamp` object to get the timestamp value as a long. Finally, we print the timestamp value to the console.
阅读全文