java.time.ZonedDateTime.now() 方法示例



描述

java.time.ZonedDateTime.now(ZoneId zone) 方法從指定時區的系統時鐘中獲取當前日期時間。

宣告

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

public static ZonedDateTime now(ZoneId zone)

引數

zone - 要使用的地區 ID,不能為空。

返回值

使用系統時鐘的當前日期時間,不能為空。

示例

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

package com.tutorialspoint;

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]
廣告
© . All rights reserved.