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



描述

java.time.Instant.now() 方法從系統時鐘獲取當前時刻。

宣告

以下是 java.time.Instant.now() 方法的宣告。

public static Instant now()

返回值

使用系統時鐘獲取的當前時刻,非空。

示例

以下示例演示了 java.time.Instant.now() 方法的用法。

package com.tutorialspoint;

import java.time.Instant;

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

      Instant instant = Instant.now();
      System.out.println(instant);   
   }
}

讓我們編譯並執行以上程式,這將產生以下結果 -

2017-03-15T09:16:53.323Z
廣告