java.time.OffsetDateTime now()方法

java.time.OffsetDateTime.now(ZoneId zone)方法从指定时区中的系统时钟获取当前日期时间。

1 语法

public static OffsetDateTime now(ZoneId zone)

2 参数

zone:要使用的区域ID,不能为null。

3 返回值

使用系统时钟的当前日期时间,不能为null。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.time.OffsetDateTime now()方法
 */
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

 

热门文章

优秀文章