How to assign a value to a timestamp in Java?
In Java, you can set values for Timestamp using the following method:
- Utilize the current timestamp:
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
- Use the specified timestamp value (in milliseconds):
long millis = 1612345678900L; // 替换为所需的时间戳值
Timestamp timestamp = new Timestamp(millis);
- Use the specified date and time.
LocalDateTime localDateTime = LocalDateTime.of(2022, 3, 1, 10, 30, 0); // 替换为所需的日期和时间
Timestamp timestamp = Timestamp.valueOf(localDateTime);
Please choose the appropriate method to assign a value to the Timestamp object based on your needs.