java.time.OffsetDateTime.of(LocalDate date, LocalTime time, ZoneOffset offset)方法

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

声明

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

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

参数

  • date - 本地日期,不为null
  • time - 当地时间,不为null
  • offset - 区域偏移量,不为null

返回值

偏移日期时间,不为null

示例

以下示例显示了java.time.OffsetDateTime.of(LocalDate date,LocalTime time,ZoneOffset offset)方法的用法。

package com.zaixian;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;

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

      LocalDate localDate = LocalDate.parse("2017-02-03");
      LocalTime localTime = LocalTime.parse("12:30:30");
      OffsetDateTime date = OffsetDateTime.of(localDate, localTime,ZoneOffset.UTC);
      System.out.println(date);  
   }
}

执行上面示例代码得到以下结果:

2017-02-03T12:30:30Z

上一篇: java.time.OffsetDateTime类 下一篇: java.time.OffsetTime类