套用格式我有一个非常基本的定时器应用程序了。我需要得到启动之间经过的时间和停止。所以我试图格式化的返回值。但我得到这个输出困惑如何在Java中
-1421687075,731
我在做什么错在这里
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnStartt){
sum=0;
count=0;
pbShow.setMaximum(Integer.parseInt(txtenter.getText()));
timer.start();
now=System.currentTimeMillis();
}
if(e.getSource()==btnStop){
timer.stop();
now=System.currentTimeMillis();
pbShow.setValue(0);
count=0;
Format formater=new DecimalFormat("#.#####");
System.out.println(formater.format((end-now)/1000d));
有一件事是你正在计算'(end-now)',但你没有设置'end':你只是再次设置'now'。所以我对你的结果有点困惑。 – CPerkins 2015-01-15 17:09:42
@CPerkins嗯,结果对我来说似乎并不奇怪;如果end没有被设置,结果_should_是否定的。 – jbowman 2015-01-15 17:13:25
@jbowman好点。 – CPerkins 2015-01-15 17:19:07