Skip to main content

Tag: Date

WorldClock and JSR310

With JSR310 (Date and Time API) in Java 8 and the small 0.7 release of WorldClock done, I can update WorldClock to the new API.

First the time used for day and night drawing:

(in WorldClockBoard)

PreJava8:

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(“GMT”));
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR);
int hours = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
int seconds = cal.get(Calendar.SECOND);

Java8:

OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
int day = now.getDayOfMonth();
int month = now.getMonthValue(); int year = now.getYear();
int hours = now.getHour();
int minutes = now.getMinute();
int seconds = now.getSecond();