Calculating the year using only milliseconds

Nice way to get the current year in Java.

int year = System.currentTimeMillis()/1000/3600/24/365.25 + 1970;

Credits are due to Ewin Makepeace at http://stackoverflow.com/questions/136419/get-integer-value-of-the-current-year-in-java

No comments:

Post a Comment