// This program determines what year it is right now and what day of the year // it is. For a non-leap year, the day-of-year will be between 1 and 365. // For a leap year, it will be between 1 and 366. // // This version fixes the "Zune" bug. public class Days3 { public static void main(String[] args) { long millis = System.currentTimeMillis(); // we subtract 1/3 to account for Pacific Time being 8 hours // behind Greenwich Mean Time; double days = toDays(millis) - 1.0 / 3.0; // we add 1 because 1/1/70 is day 1 of 1970, not day 0 int day = (int) days + 1; int year = 1970; while (day > 366 || (day == 366 && !isLeap(year))) { if (isLeap(year)) { day = day - 366; } else { day = day - 365; } year++; } System.out.println("millis = " + millis); System.out.println("days = " + days); System.out.println("year = " + year); System.out.println("day = " + day); } // returns whether or not a year is a leap year public static boolean isLeap(int year) { return year % 4 == 0; } // converts milliseconds to days public static double toDays(double millis) { return millis / 1000.0 / 60.0 / 60.0 / 24.0; } }