无名商城论坛

搜索
查看: 312|回复: 0

[其他技术] 【HC】Java计时器的实现

[复制链接]

1万

主题

1万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
32464
发表于 2022-5-8 18:33:06 | 显示全部楼层 |阅读模式
代码如下:

import static com.hutao.util.Print.*;
import java.util.Timer;
import java.util.TimerTask;

public class Main {

        public static void main(String[] args) {
                // TODO Auto-generated method stub
                long time = System.currentTimeMillis();
                TimerTask task = new TimerTask() {
                        @Override
                        public void run() {
                                String str = String.format("%1$tM:%1$tS:%1$1tL", System.currentTimeMillis() - time);
                                println(str.substring(0, 7));
                        }
                };
                new Timer().schedule(task, 1, 100);

        }
       
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表