zoukankan      html  css  js  c++  java
  • System.currentTimeMillis();

    1、  意义:

    currentTimeMillis()返回以毫秒为单位的当前时间,返回的是当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差(以毫秒为单位測量)。注意,当返回值的时间单位是毫秒时,值的粒度取决于基础操作系统,而且粒度可能更大。比如,很多操作系统以几十毫秒为单位測量时间。

    2、  用处:

    (1)      用来測试程序的执行时间:

    publicclass TestTime{

               public static void main(String[] args){

            String str = new String("0");

            long time1 =System.currentTimeMillis();

            for(int i=0;i<10000;i++){

                str += i;

            }

            long time2 =System.currentTimeMillis();

            System.out.println("for循环共用了" + (time2 - time1) + "毫秒。");

        }

    }

    (2)      控制线程时间,刷新屏幕频率:
    time1 = System.currentTimeMillis();
    你所执行的程序。。。
    time2 = System.currentTimeMillis();
    if (time2 - time1 < 60) {
    try {
    Thread.sleep(60 - (time2 - time1));
    } catch (InterruptedException e) {
    }
    }

    (3)      生成不反复的文件名称:

    public String getName(){

         Stringdate1 = null;

         SimpleDateFormatsdf1 = new SimpleDateFormat("yyyyMMddHHmmssSSS");

         date1= sdf1.format(new Date(System.currentTimeMillis()))+".txt";

         return date1;

    }

  • 相关阅读:
    正则判断是否为纯数值
    前后端加密解密crypto.js
    小程序使用iconfont字体图标
    LeetCode-Combination Sum II
    LeetCode-Combination Sum
    Google 2013 campus test-R1
    Google Codejam
    LeetCode-Count and Say
    LeetCode-Binary Tree Level Order Traversal II
    LeetCode-Binary Tree Level Order Traversal
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4515622.html
Copyright © 2011-2022 走看看