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;

    }

  • 相关阅读:
    HBase Flush 机制
    HBase 预分区 & Phoenix 加盐
    Phoenix 索引
    python 列表、元组、字典、集合的比较操作
    Redis HA
    基于 Redis 和 ZooKeeper 的分布式锁
    Ubuntu 系统设置 Swappiness 值
    Ubuntu_16.04 安装 Pyhon3.6
    Win10创意者更新秋季版升级常见问题解决方案
    如何使用注册表在Win10中调整屏幕亮度
  • 原文地址:https://www.cnblogs.com/lingyi1111/p/4423710.html
Copyright © 2011-2022 走看看