目录

static ZonedDateTime now(ZoneId zone)

描述 (Description)

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

声明 (Declaration)

以下是java.time.ZonedDateTime.now(ZoneId zone)方法的声明。

public static ZonedDateTime now(ZoneId zone)

参数 (Parameters)

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

返回值 (Return Value)

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

例子 (Example)

以下示例显示了java.time.ZonedDateTime.now(ZoneId zone)方法的用法。

package com.iowiki;
import java.time.ZonedDateTime;
import java.time.ZoneId;
public class ZonedDateTimeDemo {
   public static void main(String[] args) {
      ZonedDateTime date = ZonedDateTime.now(ZoneId.systemDefault());
      System.out.println(date);  
   }
}

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

2017-03-28T13:50:51.306+05:30[Asia/Calcutta]
↑回到顶部↑
WIKI教程 @2018