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;

}

System.currentTimeMillis();的更多相关文章

  1. System.nanoTime与System.currentTimeMillis的理解与区别

    System类代表系统,系统级的很多属性和控制方法都放置在该类的内部.该类位于java.lang包. 平时产生随机数时我们经常拿时间做种子,比如用System.currentTimeMillis的结果 ...

  2. 由system.currentTimeMillis() 获得当前的时间

    System类代表系统,系统级的很多属性和控制方法都放置在该类的内部.该类位于java.lang包. currentTimeMillis方法 public static long currentTim ...

  3. c# 实现 java 的 System.currentTimeMillis() 值

    本文地址:http://www.cnblogs.com/jying/p/3875331.html 以下一句即可实现 java 中的 System.currentTimeMillis() 值 , , , ...

  4. System.currentTimeMillis()与SystemClock.uptimeMillis()

    1.System.currentTimeMillis()获取的是系统的时间,可以使用SystemClock.setCurrentTimeMillis(long millis)进行设置.如果使用Syst ...

  5. Spring MVC exception - Invoking request method resulted in exception : public static native long java.lang.System.currentTimeMillis()

    最近在线上系统发现下面的异常信息: 2014-10-11 11:14:09 ERROR [org.springframework.web.servlet.mvc.annotation.Annotati ...

  6. System.currentTimeMillis()计算方式与时间的单位转换

    目录[-] 一.时间的单位转换 二.System.currentTimeMillis()计算方式 一.时间的单位转换 1秒=1000毫秒(ms) 1毫秒=1/1,000秒(s)1秒=1,000,000 ...

  7. System.nanoTime与System.currentTimeMillis的区别

    平时产生随机数时我们经常拿时间做种子,比如用 System.currentTimeMillis的结果,但是在执行一些循环中使用了System.currentTimeMillis,那么每次的结 果将会差 ...

  8. JAVA获取当前系统时间System.currentTimeMillis()

    System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMi ...

  9. 关于System.currentTimeMillis()

    一.时间的单位转换 1秒=1000毫秒(ms) 1毫秒=1/1,000秒(s)1秒=1,000,000 微秒(μs) 1微秒=1/1,000,000秒(s)1秒=1,000,000,000 纳秒(ns ...

随机推荐

  1. C语言头文件书写

    说一下C语言的存储类说明符: 1.Auto       只在块内变量声明中被允许,表示变量具有本地生存期. 2.Extern    出现在顶层或块的外部变量函数与变量声明中,表示声明的对象具有静态生存 ...

  2. Uva 1050 Ars Longa

    Description You have been struck with inspiration, and are designing a beautiful new art sculpture f ...

  3. DevOps on Android: 加速 App 从代码到上线

    DevOps 是一个众所周知的开发方法,其主要目的是自动化软件交付.事实上,DevOps 的目标是不断的测试,代码质量,功能开发,更容易维护版本.因此,DevOps 的一个最终目标是为开发者进行快速, ...

  4. Android Studio的一些技巧和使用注意事项(持续更新)

    1.创建一个项目之后默认是没有assets目录的,可以手动在main目录下创建一个assets目录. 2.

  5. Perl脚本学习经验(三)--Perl中ftp的使用

    使用use Net::FTP;Demo:    my $Server = '192.168.1.1';    my $User = 'admin';    my $Password = 'admin' ...

  6. Android事件分发详解(三)——ViewGroup的dispatchTouchEvent()源码学习

    package cc.aa; import android.os.Environment; import android.view.MotionEvent; import android.view.V ...

  7. 安卓高手之路之java层Binder

    很多人一提到Binder就说代理模式,人云亦云的多,能理解精髓的少. 本篇文章就从设计角度分析一下java层BInder的设计目标,以及设计思路,设计缺陷,从而驾驭它. 对于[邦德儿]的理解, 从通信 ...

  8. POJ_3176_Cow_Bowling_(数字三角形)_(动态规划)

    描述 http://poj.org/problem?id=3176 给出一个三角形,每个点可以走到它下面两个点,将所有经过的点的值加起来,问最大的和是多少. Cow Bowling Time Limi ...

  9. WordPress Bradesco Gateway插件‘falha.php’跨站脚本漏洞

    漏洞名称: WordPress Bradesco Gateway插件‘falha.php’跨站脚本漏洞 CNNVD编号: CNNVD-201309-451 发布时间: 2013-09-26 更新时间: ...

  10. 如何删除MyEclipse(eclipse)中不需要的workspace

    在安装目录下,打开eclipse/configuration/.settings,用记事本打开org.eclipse.ui.ide.prefs文件 #Wed Mar 11 14:41:21 CST 2 ...