java gregorian calendar timer
Posted
by
Ieyasu Sawada
on Stack Overflow
See other posts from Stack Overflow
or by Ieyasu Sawada
Published on 2011-01-17T11:43:43Z
Indexed on
2011/01/17
11:53 UTC
Read the original article
Hit count: 254
java
|gregorian-calendar
I have this java program which calculates the time that the person took to respond to the confirm dialog box. But it seems that both time1 and time 2 gets the same value. What have I done wrong here:
import javax.swing.JOptionPane;
import java.util.*;
public class DialogTimer{
public static void main(String args[]){
int time1, time2, milli1, milli2, sec1, sec2, timeDifference;
final int MILLISECSINSECOND =1000;
JOptionPane.showConfirmDialog(null, "Is stealing ever justified? ");
GregorianCalendar before=new GregorianCalendar();
GregorianCalendar after= new GregorianCalendar();
milli1=before.get(GregorianCalendar.MILLISECOND);
milli2=after.get(GregorianCalendar.MILLISECOND);
sec1=before.get(GregorianCalendar.SECOND);
sec2=after.get(GregorianCalendar.SECOND);
time1=MILLISECSINSECOND * sec1 + milli1;
time2=MILLISECSINSECOND * sec2 + milli2;
//timeDifference=time1 - time2;
System.out.println(time1);
System.out.println(time2);
//JOptionPane.showMessageDialog(null, "It took " + (time1 - time2) + " milliseconds for you to answer");
}
}
© Stack Overflow or respective owner