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?
For example: I have a java.sql.Timestamp
which I want to convert to java.time.Instant.
Would it be possible?
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?
For example: I have a java.sql.Timestamp
which I want to convert to java.time.Instant.
Would it be possible?
we have ready have existing methods which covert Timestamp to Instant and vice versa.
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
Check this
Converts this Timestamp object to an Instant. The conversion creates an Instant that represents the same point on the time-line as this Timestamp.
© 2022 - 2024 — McMap. All rights reserved.