class X implements ActionListener {
long d1,d2;
...
btnRecord.addActionListener(this);
btnUpdate.addActionListener(this);
...
public void ActionPerformed(ActionEvent e) {
if(e.getSource() == btnRecord) {
d1 = System.currentTimeMillise();
}else {
long diff = d1 - d2;
d2 = d1;
xyz.setText(""+diff);
}
}
...
}
long d1,d2;
...
btnRecord.addActionListener(this);
btnUpdate.addActionListener(this);
...
public void ActionPerformed(ActionEvent e) {
if(e.getSource() == btnRecord) {
d1 = System.currentTimeMillise();
}else {
long diff = d1 - d2;
d2 = d1;
xyz.setText(""+diff);
}
}
...
}
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("HH:mm:ss");
System.out.println(df.format(new Date(d2)));
to get your desired result.
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("HH:mm:ss");
System.out.println(df.format(new Date(d2)));
每次得到结果都是一样的。
有无其他方式转换成类似hh:mm:ss的格式
System.out.println(d2 + df.format(new Date(d2)));
System.out.println(( d2 +1000) + df.format(new Date(d2+1000)));
另外再看一看每次的d2值是否一样?