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;

    }

  • 相关阅读:
    私有IP地址
    Python随手记
    Selenium+Python环境搭建
    FTP- Download, upload, Delete & find files
    初学Selenium遇上的问题
    automate sap遇上的一些问题
    LR常见问题
    服务器资源监控指标
    QTP场景恢复函数
    导出excel用例
  • 原文地址:https://www.cnblogs.com/lingyi1111/p/4423710.html
Copyright © 2011-2022 走看看