JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--JAVA技术--JAVA类  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
使用StopWatch类输出时间戳
作者:未知     文章来源:www.jspcn.net
访问次数:302次     加入时间:2005年01月19日
package com.generationjava.test;

/**
* Useful when doing timings in a debug or test situation.
*/
public class StopWatch {

static public int AN_HOUR = 60 * 60 * 1000;
static public int A_MINUTE = 60 * 1000;

private long startTime = -1;
private long stopTime = -1;

/**
* Start the stopwatch.
*/
public void start() {
this.startTime = System.currentTimeMillis();
}

/**
* Stop the stopwatch.
*/
public void stop() {
this.stopTime = System.currentTimeMillis();
}

/**
* Reset the stopwatch.
*/
public void reset() {
this.startTime = -1;
this.stopTime = -1;
}

/**
* Split the time.
*/
public void split() {
this.stopTime = System.currentTimeMillis();
}

/**
* Remove a split.
*/
public void unsplit() {
this.stopTime = -1;
}

/**
* Get the time on the stopwatch. This is either the
* time between start and latest split, between start and stop,
* or the time between the start and the moment this method is called.
*/
public long getTime() {
if(stopTime != -1) {
return (System.currentTimeMillis() - this.startTime);
} else {
return this.stopTime - this.startTime;
}
}

public String toString() {
return getTimeString();
}

/**
* Get the time gap as a String.
* In hours, minutes, seconds and milliseconds.
*/
public String getTimeString() {
int hours, minutes, seconds, milliseconds;
long time = getTime();
hours = (int) (time / AN_HOUR);
time = time - (hours * AN_HOUR);
minutes = (int) (time / A_MINUTE);
time = time - (minutes * A_MINUTE);
seconds = (int) (time / 1000);
time = time - (seconds * 1000);
millis = (int) time;

return hours + "h:" + minutes + "m:" + seconds + "s:" + millis + "ms";
}
}




摘自:NET CHINA   时间:2003年1月13日
 
Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号