Reputation: 45
I was wondering what is the best way to solve this problem on java ranch.
http://www.javaranch.com/geekWatch.jsp
Thanks
Upvotes: 1
Views: 920
Reputation: 347314
Use either JodaTime or Java 8's Time API (or some other dedicated library)
LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC);
LocalDateTime then = LocalDateTime.of(1970, Month.JANUARY, 1, 0, 0);
Duration duration = Duration.between(then, now);
System.out.println(duration.toDays());
Which outputs
16748
Upvotes: 1
Reputation: 11651
The general idea can be
Now divide the value obtained in 1. by that of 2. This will give you the number of days.
Upvotes: 0