目录

OffsetDateTime atOffset(ZoneOffset offset)

描述 (Description)

java.time.Instant.atOffset(ZoneOffset offset)方法将此瞬间与偏移量组合在一起以创建OffsetDateTime。

声明 (Declaration)

以下是java.time.Instant.atOffset(ZoneOffset offset)方法的声明。

public OffsetDateTime atOffset(ZoneOffset offset)

参数 (Parameters)

offset - 要与之结合的偏移量,而不是null。

返回值 (Return Value)

从此瞬间和指定的偏移量形成的偏移日期时间,不为空。

异常 (Exceptions)

DateTimeException - 如果结果超出支持的范围。

例子 (Example)

以下示例显示了java.time.Instant.atOffset(ZoneOffset offset)方法的用法。

package com.iowiki;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
public class InstantDemo {
   public static void main(String[] args) {
      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
      System.out.println(instant);  
      ZoneOffset offset = ZoneOffset.ofHours(5);
      OffsetDateTime  date = instant.atOffset(offset);
      System.out.println(date);  
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

2017-02-03T10:37:30Z
2017-02-03T15:37:30+05:00
↑回到顶部↑
WIKI教程 @2018