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;
}
System.currentTimeMillis();的更多相关文章
- System.nanoTime与System.currentTimeMillis的理解与区别
System类代表系统,系统级的很多属性和控制方法都放置在该类的内部.该类位于java.lang包. 平时产生随机数时我们经常拿时间做种子,比如用System.currentTimeMillis的结果 ...
- 由system.currentTimeMillis() 获得当前的时间
System类代表系统,系统级的很多属性和控制方法都放置在该类的内部.该类位于java.lang包. currentTimeMillis方法 public static long currentTim ...
- c# 实现 java 的 System.currentTimeMillis() 值
本文地址:http://www.cnblogs.com/jying/p/3875331.html 以下一句即可实现 java 中的 System.currentTimeMillis() 值 , , , ...
- System.currentTimeMillis()与SystemClock.uptimeMillis()
1.System.currentTimeMillis()获取的是系统的时间,可以使用SystemClock.setCurrentTimeMillis(long millis)进行设置.如果使用Syst ...
- 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 ...
- System.currentTimeMillis()计算方式与时间的单位转换
目录[-] 一.时间的单位转换 二.System.currentTimeMillis()计算方式 一.时间的单位转换 1秒=1000毫秒(ms) 1毫秒=1/1,000秒(s)1秒=1,000,000 ...
- System.nanoTime与System.currentTimeMillis的区别
平时产生随机数时我们经常拿时间做种子,比如用 System.currentTimeMillis的结果,但是在执行一些循环中使用了System.currentTimeMillis,那么每次的结 果将会差 ...
- JAVA获取当前系统时间System.currentTimeMillis()
System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMi ...
- 关于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 ...
随机推荐
- Remove linked list elements | leetcode
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- Js 简单分页(二)
此次使用了http://www.purecss.org/ 的前端Css 效果图 上代码 //更新分页工具栏的效果展示 function updatepagetoolshow(){ //判断当前页 及 ...
- 加密算法 - RSA算法一
RSA算法原理(一) 声明: 本文转自 -- 作者: 阮一峰 (http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html) ...
- python多线程 批量下补丁
一个一个下载 要2个多小时.就直接起了个线程池.效果明显.import urllib2 from urlparse import urlparse uri = 'http://******/patch ...
- python中的单下划线和双下划线意义和作用
Python中并没有真正意义上的“私有”,类的属性的的可见性取决于属性的名字(这里的属性包括了函数).例如,以单下划线开头的属性(例如_spam),应被当成API中非公有的部分(但是注意,它们仍然可以 ...
- CycleScrollView实现轮播图
// // CycleScrollView.h // PagedScrollView // // Created by 李洪强 on 16-1-23. // Copyright (c) 201 ...
- 蓝牙RSSI计算距离
利用CoreLocation.framework很容易扫描获得周边蓝牙设备,苹果开源代码AirLocate有具体实现,下载地址: https://developer.apple.com/library ...
- MySQL 5.6 root密码丢失
windows下mysql密码忘记了 第一步:netstat -nat(可以查看mysql是否启动了,如果启动了,可以用输入net stop mysql(或者通过任务管理器结束进程)) 第二步:my ...
- C++小知识之Vector用法
tyle="margin:20px 0px 0px; font-size:14px; line-height:26px; font-family:Arial; color:rgb(51,51 ...
- openCV python 安装
0, 用 import cv 测试,发现没有安装 opencv 模块. 首先先说本开发环境是在windows xp的环境下进行搭建的. 在搭建的过程中需要保证这三个条件: 1.python需要安装py ...