stoptime.java
来自「用于统计用户在网站中的停留时间」· Java 代码 · 共 36 行
JAVA
36 行
package com.count.stoptime;
import java.util.*;
import java.text.*;
public class StopTime {
private int h=0;
private int m=0;
private int s=0;
private Date start=null;
private Date end=null;
private SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
public StopTime(){}
public void setStart(Date start){
this.start=start;
}
public void counttime(Date end){
this.end=end;
long howmuch=this.end.getTime()-start.getTime();
h=(int)(howmuch/1000/60/60);
howmuch=howmuch-h*60*60*1000;
m=(int)(howmuch/1000/60);
howmuch=howmuch-m*60*1000;
s=(int)(howmuch/1000);
}
public String getTimes(){
String times=this.h+"小时"+this.m+"分"+this.s+"秒";
return times;
}
public String getStart(){
return format.format(start);
}
public String getEnd(){
return format.format(end);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?