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



说明

java.time.OffsetDateTime.of(LocalDate date, LocalTime time, ZoneOffset offset) 方法根据指定日期时间和偏移量获取带时区偏移量的日期时间实例。

声明

以下是 java.time.OffsetDateTime.of(LocalDateTime date, ZoneOffset offset) 方法的声明。

public static OffsetDateTime of(LocalDateTime date, ZoneOffset offset)

public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset)

  • 参数

  • date - 非空的本地日期时间

offset - 非空的时区偏移量

返回值

带时区偏移量的日期时间,非空。

示例

package com.tutorialspoint;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

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

      LocalDateTime localDateTime = LocalDateTime.parse("2017-02-03T12:20:30");
      OffsetDateTime date = OffsetDateTime.of(localDateTime,ZoneOffset.UTC);
      System.out.println(date);  
   }
}

现场演示

2017-02-03T12:20:30Z
打印页面
© . All rights reserved.