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;

    }

  • 相关阅读:
    传统文化相关词组(陆续补充)
    面试题 17.09. 第 k 个数
    1544. 整理字符串
    SQL Server 2008 R2 数据库之间的数据同步热备份
    SQLServer数据库同步准实时解决方案
    SQL Server 用链接服务器 同步MySQL
    SqlServer数据库同步方案详解(包括跨网段)
    键值修饰符v-on:keyup.enter
    事件修饰符
    内连处理器里的方法2.html
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4045625.html
Copyright © 2011-2022 走看看