9

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.
  • 76,217
  • 14
  • 120
  • 142
user123475
  • 917
  • 3
  • 14
  • 27

2 Answers2

16

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
  • 424
  • 5
  • 12
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,534
  • 7
  • 43
  • 85