java.time.OffsetTime.ofInstant() 方法示例



說明

java.time.OffsetTime.ofInstant(Instant instant, ZoneId zone) 方法可從 Instant 和時區 ID 獲取一個 OffsetTime 例項。

宣告

以下是 java.time.OffsetTime.ofInstant(Instant instant, ZoneId zone) 方法的宣告。

public static OffsetTime ofInstant(Instant instant, ZoneId zone)

引數

  • instant − 要從中建立時間的瞬時,不為 null

  • zone − 時區,可能為偏移量,不為 null

返回值

偏移時間,不為 null。

示例

以下示例演示了 java.time.OffsetTime.ofInstant(Instant instant, ZoneId zone) 方法的用法。

package com.tutorialspoint;

import java.time.OffsetTime;
import java.time.Instant;
import java.time.ZoneId;

public class OffsetTimeDemo {
   public static void main(String[] args) {
 
      OffsetTime time = OffsetTime.ofInstant(Instant.now(),ZoneId.systemDefault());
      System.out.println(time);  
   }
}

讓我們編譯並執行上述程式,將生成以下結果 −

06:30:40.000050+05:30
廣告
© . All rights reserved.