java.time.OffsetTime.ofInstant(Instant instant, ZoneId zone)方法

2019-10-16 22:40:31

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.yiibai;

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