java.time.LocalTime.atOffset(ZoneOffset offset)方法

java.time.LocalTime.atOffset(ZoneOffset offset)方法将此时间与偏移量组合在一起以创建OffsetTime

声明

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

public OffsetDateTime atOffset(ZoneOffset offset)

参数

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

返回值

从此时间形成的偏移时间,不为null

示例

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

package com.zaixian;

import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;

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

      LocalTime time = LocalTime.parse("12:30:30");
      System.out.println(time);  
      OffsetTime time1 = time.atOffset(ZoneOffset.ofHours(2));
      System.out.println(time1);  
   }
}

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

12:30:30
12:30:30+02:00

上一篇: java.time.LocalTime类 下一篇: java.time.MonthDay类