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;

    }

  • 相关阅读:
    [VC++入门]C++中常用的运算符及微软自定义类型
    搜索引擎蜘蛛爬虫原理
    Enterprise Library 5.0
    Installshield 12 中文系列教程之 定义安装必要条件
    installshield脚本
    c# 事物处理
    InStallShield网络资源参考
    Could not execute query against OLE DB provider 'OraOLEDB.Oracle'
    frameset小结
    最痛心的距离
  • 原文地址:https://www.cnblogs.com/lingyi1111/p/4423710.html
Copyright © 2011-2022 走看看