I am trying to write a program that simply prints the current date. so all i need is year, month, and day. I am not allowed to use any date, calendar, gregorian calendar, or time classes in order to obtain the current date. All i am able to use is System.currentTimeMillis()
to get the current time in milli seconds since epoch and java.util.TimeZone.getDefault().getRawOffset()
to account for my time zone since epoch.
What i have tried so far is taking the current time in milliseconds and dividing by 1000 to get seconds and then 60 to get minutes and then 60 to get hours and so on. Which works fine until i get down to days which is 18184 since epoch january 1, 1970. I cant simply divide the days completely by 30 or 31 because not all months have 30 or 31 days. i can't find years either because of leap years being 365 or 364 days in them.
class JulianDate {
static void main() {
long currentMilli = System.currentTimeMillis() + java.util.TimeZone.getDefault().getRawOffset();
long seconds = currentMilli / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
System.out.println("Days since epoch : " + days);
}
}
I need the end code to simply print 10/15/2019
or October 15, 2019
. the format doesnt matter i just need it to print the current day, month, and year based on the epoch milliseconds