Search code examples
javatimemillisecondsseconds

Java currentTimeMillis() conversion to seconds not working?


Im trying to convert milliseconds to seconds with System.currentTimeMillis();

System.out.println((int) System.currentTimeMillis() / 1000);

The output is 730750 and increasing by 1. How can i get seconds starting from 0?

**UPDATE: Now i understand the problem and thank you for answering it.


Solution

  • System.currentTimeMillis() is from January 1, 1970. It will take today's time and subtract it from midnight January 1, 1970. That is why it is so many seconds.