Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloprado/6f192e2f293fbc752674dcec076943e1 to your computer and use it in GitHub Desktop.
Save juanpabloprado/6f192e2f293fbc752674dcec076943e1 to your computer and use it in GitHub Desktop.
LocalDate and LocalTime plus/minus methods on the Java Shell tool
jshell> LocalDate ld = LocalDate.now();
ld ==> 2019-04-23
jshell> // All plus methods
jshell> ld = ld.plusYears(1).plusMonths(12).plusWeeks(52).plusDays(365);
ld ==> 2023-04-22
jshell> // All minus methods
jshell> ld = ld.minusYears(1).minusMonths(12).minusWeeks(52).minusDays(365);
ld ==> 2019-04-24
jshell> LocalTime lt = LocalTime.now();
lt ==> 22:09:45.241958
jshell> // All plus methods
jshell> lt = lt.plusHours(18765).plusMinutes(525949).plusSeconds(0).plusNanos(0);
lt ==> 00:58:45.241958
jshell> lt = lt.minusHours(1).minusMinutes(1).minusSeconds(1).minusNanos(1);
lt ==> 23:57:44.241957999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment