Import Java.util.Calendar;
Import Java.util.Date;
Import Java.util.Timer;
Import Java.util.TimerTask;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
/**
*
* @author Wesley
* @date January 28, 2015
*
*/
public class Countdown {
Private Long longtime;
Private Long currenttime;
Private Long disttime;
Private Long day, hour, minutes, seconds;
Public Countdown () {
Cdown ();
}
public void Cdown () {
Timer timer = new timer ();
JFrame JF = new JFrame ();
final JLabel jl = new JLabel ();
Jf.add (JL);
jf.setvisible (true);
jf.setsize (350, 100);
jf.settitle ("Countdown Software");
jf.setdefaultcloseoperation (jframe.exit_on_close);
Timer.schedule (New TimerTask () {
@Override
public void run () {
Calendar cal = Calendar.getinstance ();
//set a scheduled time
cal.set (2015, 0, 28, 17, 30, 0);//0 representative January, 11 for December
//Returns the number of milliseconds of the calendar element to a specified time.
longtime = Cal.gettimeinmillis ();
//Returns the number of milliseconds represented by this Date object since January 1, 1970 00:00:00 GMT.
currenttime = new Date (). GetTime ();
//distance of time
disttime = longtime-currenttime;
//Get Days
day = ((disttime/1000)/(3600 * 24));
//Get the number of hours
hour = ((disttime/1000)-day * 86400)/3600;
//Get the number of minutes
minutes = ((disttime/1000)-day * 86400-hour * 3600)/60;
//Get the number of seconds
seconds = (disttime/1000)-day * 86400-hour * 3600
-minutes * 60;
jl.settext ("Countdown" + Day + "days" + Hour + "hours:" + minutes
+ "minutes:" + seconds + "seconds");
}
}, 0, 1000);
}
public static void Main (string[] args) {
New Countdown ();
}
}
Java Implementation Countdown source sharing