2015-01-15 86 views
1

套用格式我有一个非常基本的定时器应用程序了。我需要得到启动之间经过的时间和停止。所以我试图格式化的返回值。但我得到这个输出困惑如何在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)); 
+0

有一件事是你正在计算'(end-now)',但你没有设置'end':你只是再次设置'now'。所以我对你的结果有点困惑。 – CPerkins 2015-01-15 17:09:42

+0

@CPerkins嗯,结果对我来说似乎并不奇怪;如果end没有被设置,结果_should_是否定的。 – jbowman 2015-01-15 17:13:25

+0

@jbowman好点。 – CPerkins 2015-01-15 17:19:07

回答

1

您的代码将无法编译,但基于还有什么我要假设你的说法now=System.currentTimeMillis();在第二块如果块应该是:end=System.currentTimeMillis();

+0

ooppss谢谢 – user3733078 2015-01-15 17:11:20

+0

八分钟后我会接受你的回答 – user3733078 2015-01-15 17:12:37

+0

@ user3733078没问题! – jbowman 2015-01-15 17:15:26