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 ...
随机推荐
- vs2010 未能正确加载方案中的一个或多个项目
Visual studio在打开解决方案时,往往会碰到一个这样的错误,提示说:未能正确加载方案中的一个或多个项目: 我们可以通过以下步骤来解决该问题:首先,在相应的sln类型文件上点击右键,选择用记事 ...
- 【2011 Greater New York Regional 】Problem I :The Golden Ceiling
一道比较简单但是繁琐的三维计算几何,找错误找的我好心酸,没想到就把一个变量给写错了 = =: 题目的意思是求平面切长方体的截面面积+正方体顶部所遮盖的面积: 找出所有的切点,然后二维凸包一下直接算面积 ...
- c语言开源项目--SQLite学习资料总结
同行博客: 1.http://www.cnblogs.com/hustcat/category/175618.html; 2.http://blog.csdn.net/zhoudaxia/articl ...
- JBPM4.4部署到tomcat6异常解决办法
java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.ser ...
- 创建用于自定义SharePoint解决方案部署的Visual Studio项目
转:http://soft.zdnet.com.cn/software_zone/2007/0903/488083.shtml 在基于SharePoint的开发中,我们通常会在WSS的TEMPLATE ...
- Action中取得request,session的四种方式
Action中取得request,session的四种方式 在Struts2中,从Action中取得request,session的对象进行应用是开发中的必需步骤,那么如何从Action中取得这些对象 ...
- EXT 组件一些属性与方法(Tree)
1.Ext.tree.TreePanel 主要配置项: root:树的根节点. rootVisible:是否显示根节点,默认为true. useArrows:是否在树中使用Vista样式箭头,默认为f ...
- web调试工具
Fiddler是最强大最好用的Web调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据. 使用Fiddler无论对开发还是测试来说,都有很大 ...
- 【转】qtp安装时问题
1.安装qtp后要重启机器. 2.插件选择错误, 处理方式:重新启动QTP,勾选 WEB插件; 3.在安装QTP后,或者禁用IE浏览器里的一些ActiveX控件后,正常录制QTP时,对象识别不了;(保 ...
- JS小知识点----基本包装类型和引用类型
var s1 = "some text"; s1.color = "red"; alert(s1.color); //弹出 underfined var s1 ...