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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

TimeUnit使用

發布時間:2023/12/1 综合教程 33 生活家
生活随笔 收集整理的這篇文章主要介紹了 TimeUnit使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

常用顆粒度

TimeUnit.DAYS          //天
TimeUnit.HOURS         //小時
TimeUnit.MINUTES       //分鐘
TimeUnit.SECONDS       //秒
TimeUnit.MILLISECONDS  //毫秒

顆粒度轉換

public long toMillis(long d)    //轉化成毫秒
public long toSeconds(long d)  //轉化成秒
public long toMinutes(long d)  //轉化成分鐘
public long toHours(long d)    //轉化成小時
public long toDays(long d)     //轉化天
import java.util.concurrent.TimeUnit;public class TimeUnitTest {public static void main(String[] args) {//convert 1 day to 24 hourSystem.out.println(TimeUnit.DAYS.toHours(1));//convert 1 hour to 60*60 second.System.out.println(TimeUnit.HOURS.toSeconds(1));//convert 3 days to 72 hours.System.out.println(TimeUnit.HOURS.convert(3, TimeUnit.DAYS));}}

可代替sleep

import java.util.concurrent.TimeUnit;public class ThreadSleep {public static void main(String[] args) {Thread t = new Thread(new Runnable() {private int count = 0;@Overridepublic void run() {for (int i = 0; i < 10; i++) {try {// Thread.sleep(500); //sleep 單位是毫秒TimeUnit.SECONDS.sleep(1); // 單位可以自定義,more convinent} catch (InterruptedException e) {e.printStackTrace();}count++;System.out.println(count);}}});t.start();}
}

總結

以上是生活随笔為你收集整理的TimeUnit使用的全部內容,希望文章能夠幫你解決所遇到的問題。

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