【Java】TimeUnit的使用
TimeUnit 表示给定单元粒度的时间段
常用的颗粒度:
TimeUnit.DAYS
天TimeUnit.HOURS
小时TimeUnit.MINUTES
分钟TimeUnit.SECONDS
秒TimeUnit.MILLISECONDS
毫秒
颗粒度转换
1 天转换为 24 小时
TimeUnit.DAYS.toHours(1)
1 小时转换为 60*60 秒
TimeUnit.HOURS.toSeconds(1)
3 天转换为 72 小时
TimeUnit.HOURS.convert(3, TimeUnit.DAYS)
线程等待
可替代
Thread.sleep()
线程等待 1 秒
TimeUnit.SECONDS.sleep(1);