zoukankan      html  css  js  c++  java
  • System类用法currentTimeMillis

    import java.text.SimpleDateFormat;
    import java.util.Date;
     
    public class aaaa {
        public static void main(String[] args) throws Exception {
            //-------用途一 计算某任务 耗费的毫秒
            long start = System.currentTimeMillis();
            for (int i = 0; i < 5; i++) {
                Thread.sleep(10);
            }
            long end = System.currentTimeMillis();
            System.out.println("for循环耗时" + (end - start) + "毫秒");
     
            //--------用途二  获得当前的系统时间
            Date nowTime = new Date(System.currentTimeMillis());
            SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd");
            String now = sdFormatter.format(nowTime);
            System.out.println(now);// 时间的输出
             
            //-------用途三:用当前毫秒数给文件命名等
            File f = new File("c:\"+System.currentTimeMillis() + "");
            f.createNewFile();
             
            //其他用途,比如随机数的种子数等
        }
    }
  • 相关阅读:
    XidianOJ 1073 Nunchakus
    XidianOJ 1024 2的幂次表示
    XidianOJ 1072 National Disaster
    XidianOJ 1093 一元三次方程
    中国剩余定理
    bzoj2818(欧拉函数递推)
    poj2311(博弈论,sg函数)
    contesthunter#46-A(分块)
    Tree,点分治
    poj3580(splay 毒瘤题)
  • 原文地址:https://www.cnblogs.com/xzcBY/p/7569552.html
Copyright © 2011-2022 走看看