java.time.ZonedDateTime.ofStrict() 方法

描述

java.time.ZonedDateTime.ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) 方法获取 ZonedDateTime 的实例,严格验证本地日期时间、偏移量和区域 ID 的组合。


声明

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

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

参数

  • localDateTime − 本地日期时间,不为空。

  • offset − 区域偏移量,不为空。

  • zone − 时区,不为空。


返回值

分区日期时间,不为空。


示例

下面的例子展示了 java.time.ZonedDateTime.ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId 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