Hi all,
I'm not looking for the answer but rather a point in the right direction would be most welcome.
I have used two methods to tell the current time from System.currentTimeMillis()
The first method using the java.util.Date gives me the correct time, but the second method (using long calculation) gives me the time - 1 hour. e.g: util.Date giving 9:30am and the long method giving 8:30am
I can't figure out why the two times would be different.
Any and all advice welcome.
Code below:
import java.util.Date;
class Q8
{
public static void main (String[]args)
{
long currentMillisecond = System.currentTimeMillis();
Date currentDate = new Date(currentMillisecond);
System.out.println("The current date is: " + currentDate);
long seconds = currentMillisecond/1000;
long currentSecond = seconds%60;
long minutes = seconds/60;
long currentMinute = minutes%60;
long hours = minutes/60;
long currentHour = hours%24;
System.out.println("The current time is: " + currentHour + ":" + currentMinute + ":" + currentSecond);
}
}