java.time.ZonedDateTime.of(LocalDateTime date, ZoneId zone)方法

java.time.ZonedDateTime.of(LocalDateTime date,ZoneId zone)方法從日期時間和時區獲取ZonedDateTime的實例。

聲明

以下是java.time.ZonedDateTime.of(LocalDateTime date,ZoneId zone)方法的聲明。

public static ZonedDateTime of(LocalDateTime date, ZoneId zone)

參數

  • date - 本地日期時間,不為null
  • zone - 時區,不為null

返回值

分區日期時間,不為null

示例

以下示例顯示了java.time.ZonedDateTime.of(LocalDateTime date,ZoneId zone)方法的用法。

package com.zaixian;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;

public class ZonedDateTimeDemo {
   public static void main(String[] args) {

      ZonedDateTime date = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault());
      System.out.println(date);
   }
}

編譯並運行上面的程式,這將產生以下結果 -

2017-03-28T13:57:45.878+05:30[Asia/Calcutta]

上一篇: java.time.ZonedDateTime類 下一篇: java.time.ZoneId類