日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java tick_Java中的Clock tick()方法

發布時間:2023/12/1 java 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java tick_Java中的Clock tick()方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

可以使用tick()Java中Clock類中的方法在所需的時間范圍內舍入基本時鐘的瞬間。此方法需要兩個參數,即基本時鐘和滴答的持續時間。同樣,返回在所需持續時間內四舍五入的基本時鐘時刻。

演示此的程序如下所示-

示例import?java.time.*;

public?class?Main?{

public?static?void?main(String[]?args)?{

Clock?bClock?=?Clock.systemDefaultZone();

Instant?i?=?bClock.instant();

System.out.println("The?Instant?of?the?base?clock?is:?"?+?i);

Clock?c1?=?Clock.tick(bClock,?Duration.ofSeconds(45));

System.out.println("Instant?of?the?first?clock?with?duration?45?seconds?is:?"?+?c1.instant());

Clock?c2?=?Clock.tick(bClock,?Duration.ofHours(45));

System.out.println("Instant?of?the?first?clock?with?duration?45?hours?is:?"?+?c2.instant());

Clock?c3?=?Clock.tick(bClock,?Duration.ofDays(45));

System.out.println("Instant?of?the?first?clock?with?duration?45?days?is:?"?+?c3.instant());

}

}

輸出結果The?Instant?of?the?base?clock?is:?2019-02-06T12:26:22.488Z

Instant?of?the?first?clock?with?duration?45?seconds?is:?2019-02-06T12:26:15Z

Instant?of?the?first?clock?with?duration?45?hours?is:?2019-02-05T12:00:00Z

Instant?of?the?first?clock?with?duration?45?days?is:?2019-01-14T00:00:00Z

現在讓我們了解上面的程序。

使用方法將基本時鐘的時刻四舍五入至所需的持續時間tick()。然后使用instant()方法顯示。演示這的代碼片段如下-Clock?bClock?=?Clock.systemDefaultZone();

Instant?i?=?bClock.instant();

System.out.println("The?Instant?of?the?base?clock?is:?"?+?i);

Clock?c1?=?Clock.tick(bClock,?Duration.ofSeconds(45));

System.out.println("Instant?of?the?first?clock?with?duration?45?seconds?is:?"?+?c1.instant());

Clock?c2?=?Clock.tick(bClock,?Duration.ofHours(45));

System.out.println("Instant?of?the?first?clock?with?duration?45?hours?is:?"?+?c2.instant());

Clock?c3?=?Clock.tick(bClock,?Duration.ofDays(45));

System.out.println("Instant?of?the?first?clock?with?duration?45?days?is:?"?+?c3.instant());

總結

以上是生活随笔為你收集整理的java tick_Java中的Clock tick()方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。