//显示时间
Date d=new Date(System.currentTimeMillis()-startTime.getTime()-28800000);
这句话啥意思?为什么-28800000? 下面是全部代码:
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Date;
import java.text.SimpleDateFormat; public class StopWatch extends JFrame {
JButton btnStart, btnStop;
JLabel label;
Timer timer; public StopWatch() {
label = new JLabel("0000:00.000");
btnStart = new JButton("start");
btnStop = new JButton("stop");
final int delay = 100;
final Date startTime = new Date();
final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.S");
final Action taskPerformer = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
// 显示时间
Date d = new Date(System.currentTimeMillis()
- startTime.getTime() - 28800000);
System.out.println(d);
label.setText(sdf.format(d));
label.repaint();
}
};
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
startTime.setTime(new Date().getTime());
timer = new Timer(delay, taskPerformer);
timer.start();
}
});
btnStop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (timer != null && timer.isRunning())
timer.stop();
}
}); Container c = getContentPane();
c.add(label, BorderLayout.NORTH);
c.add(btnStart, BorderLayout.CENTER);
c.add(btnStop, BorderLayout.SOUTH);
} public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
}); } private static void createAndShowGUI() {
StopWatch window = new StopWatch();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
}
}
Date d=new Date(System.currentTimeMillis()-startTime.getTime()-28800000);
这句话啥意思?为什么-28800000? 下面是全部代码:
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Date;
import java.text.SimpleDateFormat; public class StopWatch extends JFrame {
JButton btnStart, btnStop;
JLabel label;
Timer timer; public StopWatch() {
label = new JLabel("0000:00.000");
btnStart = new JButton("start");
btnStop = new JButton("stop");
final int delay = 100;
final Date startTime = new Date();
final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.S");
final Action taskPerformer = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
// 显示时间
Date d = new Date(System.currentTimeMillis()
- startTime.getTime() - 28800000);
System.out.println(d);
label.setText(sdf.format(d));
label.repaint();
}
};
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
startTime.setTime(new Date().getTime());
timer = new Timer(delay, taskPerformer);
timer.start();
}
});
btnStop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (timer != null && timer.isRunning())
timer.stop();
}
}); Container c = getContentPane();
c.add(label, BorderLayout.NORTH);
c.add(btnStart, BorderLayout.CENTER);
c.add(btnStop, BorderLayout.SOUTH);
} public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
}); } private static void createAndShowGUI() {
StopWatch window = new StopWatch();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
}
}
至于为什么要这样做 我也不是很清楚了
感觉是1970年1月1日8点
减掉8个小时吧
呵呵
至于为什么要这样做 我也不是很清楚了
感觉是1970年1月1日8点
减掉8个小时吧
呵呵
至于为什么要这样做 我也不是很清楚了
感觉是1970年1月1日8点
减掉8个小时吧
呵呵