1 Star 0 Fork 0

晨度 / FoundationStudy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TimeUnitDemo.java 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
晨度 提交于 2022-01-08 16:00 . 多线程案例
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();
}
}
Java
1
https://gitee.com/zhuayng/foundation-study.git
git@gitee.com:zhuayng/foundation-study.git
zhuayng
foundation-study
FoundationStudy
develop

搜索帮助