This is one of the best programs I've read so far. Its a simple program but the logic is awesome. The currentTimeMillis method in the System class returns the current time in millisecond elapsed since the time 00:00:00 in January 1970 when Unix was formally launched. It is called as 'Unix epoch'.
[This program is from Java programming by Daniel liang.]
public class ShowCurrentTime
{
public static void main(String args[])
{
long totalMilliseconds=System.currentTimeMillis();
long totalSeconds=totalMillisecond/1000;
int currentSecond=(int)(totalSeconds%60);
long totalMinutes=totalSeconds/60;
int currentMinute=(int)(totalMinutes%60);
long totalHours=totalMinutes/60;
int currentHour=(int)(totalHours%24);
System.out.println("Current time is:"+currentHour+""+currentMinute+""+currentSecond+" "GMT");
}
}
KILL THE FILL
12 years ago
No comments:
Post a Comment