java.time.OffsetDateTime.now(ZoneId zone)
方法从指定时区中的系统时钟获取当前日期时间。
声明
以下是java.time.OffsetDateTime.now(ZoneId zone)
方法的声明。
public static OffsetDateTime now(ZoneId zone)
参数
zone
- 要使用的区域ID,不能为null
。
返回值
使用系统时钟的当前日期时间,不能为null
。
示例
以下示例显示了java.time.OffsetDateTime.now(ZoneId zone)
方法的用法。
package com.zaixian;
import java.time.OffsetDateTime;
import java.time.ZoneId;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.now(ZoneId.systemDefault());
System.out.println(date);
}
}
编译并运行上面的程序,这将产生以下结果 -
2017-03-21T12:37:15.477+05:30