java.time.OffsetDateTime.toInstant() 方法示例



說明

java.time.OffsetDateTime.toInstant() 方法將此日期時間轉換為 Instant。

宣告

以下是 java.time.OffsetDateTime.toInstant() 方法的宣告。

public Instant toInstant()

返回值

表示同一 instant 的 Instant,不為 null。

示例

以下示例顯示瞭如何使用 java.time.OffsetDateTime.toInstant() 方法。

package com.tutorialspoint;

import java.time.OffsetDateTime;

public class OffsetDateTimeDemo {
   public static void main(String[] args) {
 
      OffsetDateTime date = OffsetDateTime.now();
      System.out.println(date.toInstant());  
   }
}

讓我們編譯並執行上面的程式,這會產生以下結果 -

2017-03-21T08:45:08.755Z
廣告
© . All rights reserved.