java.time.ZonedDateTime.of() 方法示例



說明

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 - 非空的本地日期時間

  • zone - 非空的時區

返回值

非空的帶時區的日期時間。

示例

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

package com.tutorialspoint;

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]
廣告
© . All rights reserved.