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



描述

java.time.ZonedDateTime.ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) 方法嚴格驗證本地日期時間、偏移量和區域 ID 組合,獲取 ZonedDateTime 的例項。

宣告

以下是 java.time.ZonedDateTime.ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) 方法的宣告。

public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone)

```java

  • 引數

  • localDateTime − 非空的本地日期時間。

  • offset − 非空的區域偏移量。

zone − 非空的時區。

返回值

非空的區域日期時間。

示例

package com.tutorialspoint;

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

public class ZonedDateTimeDemo {
   public static void main(String[] args) {
 
      ZonedDateTime date = ZonedDateTime.ofStrict(LocalDateTime.now(), ZoneOffset.UTC, ZoneId.of("Z"));
      System.out.println(date);  
   }
}

即時演示

2017-03-28T14:12:19.482Z
列印頁面
廣告