Number of days from year zero to today
How can I find out the number of days that have passed from the "beginning of time" (0 year, 1 month, 1 day) to today?
1
Author: Heorhii Lysenko, 2017-05-25
2 answers
The option I found here:
Calendar cal = Calendar.getInstance();
cal.set(0, 1, 1);
long diff = new Date(System.currentTimeMillis() - cal.getTime().getTime();
System.out.println ("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
There is a variant with JodaTime:
DateTime date1 = new DateTime(0, 1, 1, 0, 0);
DateTime date2 = new DateTime(System.currentTimeMillis());
int days = Days.daysBetween(date1, date2).getDays();
0
Author: Vladimir Parfenov, 2017-05-25 11:17:15
Head-on:
int days=System.currentTimeMillis()/(24*60*60*1000L);
-1
Author: Barmaley, 2017-05-25 12:25:26