11

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?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
user123475
  • 1,065
  • 4
  • 17
  • 29

2 Answers2

17

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
Dipak Prajapati
  • 486
  • 5
  • 13
0

Check this

public Instant toInstant()

Converts this Timestamp object to an Instant. The conversion creates an Instant that represents the same point on the time-line as this Timestamp.

Basit Anwer
  • 6,742
  • 7
  • 45
  • 88