Introduction
I wanted to get my computer's current time in the format of HH:MM:SS. Although I tried a lot of different methods, they are all giving me the same result.
Code
long milliseconds = System.currentTimeMillis();
int seconds = (int) (milliseconds / 1000) % 60 ;
int minutes = (int) ((milliseconds / (1000*60)) % 60);
int hours = (int) ((milliseconds / (1000*60*60)) % 24);
System.out.println(hours +":" + minutes+ ":"+ seconds);
Result
12:42:34 but my computer's current time is 8:42:34
What I want
But the time is different from my computer's current time. Why?