- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 瞬時
- java.time - 日期
- java.time - 日期時間
- java.time - 時間
- java.time - 月日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 時間段
- java.time - 年份
- java.time - 年月
- java.time - 時區日期時間
- java.time - 時區識別符號
- java.time - 時區偏移量
- java.time 包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 討論
java.time.Instant.now() 方法示例
描述
java.time.Instant.now(Clock clock) 方法從指定時鐘獲取當前時刻。
宣告
以下是 java.time.Instant.now(Clock clock) 方法的宣告。
public static Instant now(Clock clock)
java.time.Instant java.time.Instant.now(Clock clock)
引數
clock - 要使用的時鐘(非 null)。
返回值
non null - 使用指定時鐘獲取的當前時刻。
示例
package com.tutorialspoint;
import java.time.Clock;
import java.time.Instant;
public class InstantDemo {
public static void main(String[] args) {
Instant instant = Instant.now(Clock.systemUTC());
System.out.println(instant);
}
}
讓我們編譯並執行以上程式,將生成以下結果 -
2017-03-15T09:18:34.062Z
廣告