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 ...
随机推荐
- POJ 1035 Spell checker 简单字符串匹配
在输入的单词中删除或替换或插入一个字符,看是否在字典中.直接暴力,172ms.. #include <stdio.h> #include <string.h> ]; ][], ...
- 支付宝Demo 报错
支付宝SDK-------DEMO第一次编译肯定是会报错的: 修正的方法为: 打开项目属性->Build Settings 找到 Library SearchPaths 看见里面的参数了 ...
- HTML5+CSS3鼠标悬停图片特效
点击预览效果 下载该特效: HTML5+CSS3鼠标悬停图片特效.zip 特效说明: 一款HTML5+CSS3鼠标悬停图片事件网页特效,集合了最流行鼠标悬停图片文字.图片动画移动 ...
- ACM俱乐部算法基础练习赛(1)
A: 水题 代码: #include<cstdio> #include<algorithm> using namespace std; ]; int n,m,c; int ma ...
- [topcoder]IncreasingSubsequences
http://community.topcoder.com/stat?c=problem_statement&pm=7753&rd=10672 http://community.top ...
- 解决ASP.NET MVC AllowAnonymous属性无效导致无法匿名访问控制器的问题
在ASP.NET MVC项目中,一般都要使用身份验证和权限控制,但总有部分网页是可以匿名访问的.使用AllowAnonymous属性就可以指定需要匿名访问的控制器,从而跳过身份验证. 但是今天却遇到一 ...
- oracle 回收站
oracle10g,在pl/sql中选中删除后会出现类似:BIN$nJ5JuP9cQmqPaArFei384g==$0的表. 1.查看回收站 select * from user_recyclebin ...
- wpa_supplicant 配置与应用
概述 wpa_supplicant是wifi客户端(client)加密认证工具,和iwconfig不同,wpa_supplicant支持wep.wpa.wpa2等完整的加密认证,而iwconfig只能 ...
- Java基础(二十三)GUI图形界面编程(Java基础完)
这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...
- Keepass 2.x 之 同步与触发器
同步 之前用的 Keepass 1.x, 要实现工作电脑和个人电脑上的数据库文件同步,使用的是第三方的网盘同步.但有个问题就是,个人不习惯设置同步网盘开机启动,所以有时候工作电脑上的改动还没有同步上传 ...