目录

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

描述 (Description)

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

声明 (Declaration)

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

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

参数 (Parameters)

  • date - 本地日期,不为null

  • time - 当地时间,不为空

  • offset - 区域偏移量,不为空

返回值 (Return Value)

偏移日期时间,不为空。

例子 (Example)

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

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018