代码拉取完成,页面将自动刷新
package com.yxkj.juc.other;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
* @author :zhuyang
* @date :2022-01-08 14:53
* @description:时间单元
* @modified By:
* @version: 1.0
*/
@Service
public class TimeUnitDemo {
/**
* @Description: 转换示列
* @Author: zhuyang
* @Date: 2022/1/8 14:54
* @return: void
**/
public void convert(){
//将1天转换为小时
System.out.println("将1天转换为小时: "+TimeUnit.DAYS.toHours(1));
//答案:24
//将1小时转换为秒
System.out.println("将1小时转换为秒: "+TimeUnit.HOURS.toSeconds(1));
//答案: 3600
//将3天转换为小时
System.out.println("将3天转换为小时: "+TimeUnit.HOURS.convert(3,TimeUnit.DAYS));
//答案: 72
}
/**
* @Description: 睡眠方式
* @Author: zhuyang
* @Date: 2022/1/8 15:04
* @return: void
**/
public void sleep(){
new Thread(new Runnable() {
@Override
public void run() {
long currentTimeMillis = System.currentTimeMillis();
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("睡眠了几秒钟:"+TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()-currentTimeMillis));
}
}).start();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。