long seconds = System.currentTimeMillis()/1000; long second = seconds%60; long minute = seconds/60%60; long hour = seconds/3600%24; textView.setText(hour+":"+minute+":"+second); 

On computer 20.00, the output will be:

15: 0: 0

The problem is that the clock is 5 hours behind. What am I doing wrong? Through the calendar it is not necessary, I need to figure out exactly this. I understand this because of the time zone?

  • 2
    Do you even know what System.currentTimeMillis() returns? - Roman

1 answer 1

If you look at the description of the method, you will see the following:

  • @return the difference, measured in milliseconds, between
  • the current time and midnight, January 1, 1970 UTC.

those. timestamp comes in the UTC + 0 time zone, because of this, there are discrepancies with local time.

  • Still, currentTimeMillis returns the number of milliseconds, it's just a number, it does not have a time zone. Just the moment of time when the countdown of this number began, it is accepted to express in UTC. It is easy to show that this is also the number of milliseconds that have elapsed since January 1, 1970 03:00:00 UTC + 3, but this does not cause currentTimeMillis be in the UTC + 3 time zone. - Roman
  • Thank you for your comment. Yes, of course, the number can not be in some time zone. - Artem Konovalov