Java 中的即时时间戳
Timestamp to Instant in Java
I have a pojo which has a filed type as Instant. I want to set the
Instant getting it from TimsStamp. Would it be possible?
例如:我有一个 java.sql.Timestamp
,我想将其转换为 java.time.Instant.
可以吗?
检查这个
Converts this Timestamp object to an Instant.
The conversion creates an Instant that represents the same point on the time-line as this Timestamp.
我们已经准备好现有的方法,可以将 Timestamp 转换为 Instant,反之亦然。
Instant instant = Instant.now(); // get The current time in instant object
Timestamp t=java.sql.Timestamp.from(instant); // Convert instant to Timestamp
Instant anotherInstant=t.toInstant(); // Convert Timestamp to Instant
I have a pojo which has a filed type as Instant. I want to set the Instant getting it from TimsStamp. Would it be possible?
例如:我有一个 java.sql.Timestamp
,我想将其转换为 java.time.Instant.
可以吗?
检查这个
Converts this Timestamp object to an Instant. The conversion creates an Instant that represents the same point on the time-line as this Timestamp.
我们已经准备好现有的方法,可以将 Timestamp 转换为 Instant,反之亦然。
Instant instant = Instant.now(); // get The current time in instant object
Timestamp t=java.sql.Timestamp.from(instant); // Convert instant to Timestamp
Instant anotherInstant=t.toInstant(); // Convert Timestamp to Instant