9

フィールドタイプが Instant の pojo があります。TimsStamp から取得する Instant を設定したい。それは可能でしょうか?

例: にjava.sql.Timestamp変換しjava.time.Instant.たい がありますか?

4

2 に答える 2

16

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
于 2016-07-14T04:27:01.403 に答える
0

これをチェックして

public Instant toInstant()

この Timestamp オブジェクトを Instant に変換します。変換により、タイムライン上のこの Timestamp と同じ時点を表す Instant が作成されます。

于 2016-07-14T04:22:34.423 に答える