Time travel 101

  • Post category:icalJava

Suppose you take 2:30 AM at some random day in the year, and add 366 times one day to it, when do you end up? Yes… 367 times if it’s a leap year, wise guys. But still, when do you end up?

Calendar cal = new GregorianCalendar(2020, 11-1, 1, 2, 30);
cal.setTimeZone(TimeZone.getTimeZone("Europe/Rome"));
ZonedDateTime zdt = ZonedDateTime.of(2020, 11, 1, 2, 30, 00, 00, ZoneId.of("Europe/Rome"));
for (int i = 0; i < 366; i++) {
	System.out.println(cal.toInstant() + "   " + zdt);
			
	cal.add(Calendar.DATE, 1);
	zdt = zdt.plusDays(1);
}

Take a guess before reading on!

(more…)

Continue ReadingTime travel 101