Skip to content

Instantly share code, notes, and snippets.

@lorenzoongithub
Created June 3, 2016 21:02
Show Gist options
  • Save lorenzoongithub/127278b6478e9b35e3fca13b566f88b5 to your computer and use it in GitHub Desktop.
Save lorenzoongithub/127278b6478e9b35e3fca13b566f88b5 to your computer and use it in GitHub Desktop.
//
// An example of java 8 new Date/Time API.
//
var LocalDate = Java.type('java.time.LocalDate');
var Month = Java.type('java.time.Month');
var ChronoUnit = Java.type('java.time.temporal.ChronoUnit');
var today = LocalDate.now();
var firstDayThisYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
var days = ChronoUnit.DAYS.between(firstDayThisYear, today);
days + " days have passed since the beginning of the year."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment