Skip to content

Instantly share code, notes, and snippets.

@juanpabloprado
Created April 27, 2019 21:02
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/385604170089ae96c10eae247de14ab3 to your computer and use it in GitHub Desktop.
Save juanpabloprado/385604170089ae96c10eae247de14ab3 to your computer and use it in GitHub Desktop.
Period between method on the Java Shell tool
shell> String WAR_OF_1812_START_DATE = "1812-06-18";
WAR_OF_1812_START_DATE ==> "1812-06-18"
jshell> String WAR_OF_1812_END_DATE = "1815-02-18";
WAR_OF_1812_END_DATE ==> "1815-02-18"
jshell> import java.time.LocalDate;
jshell> LocalDate warBegins = LocalDate.parse(WAR_OF_1812_START_DATE);
warBegins ==> 1812-06-18
jshell> LocalDate warEnds = LocalDate.parse(WAR_OF_1812_END_DATE);
warEnds ==> 1815-02-18
jshell> Period period = Period.between(warBegins, warEnds);
period ==> P2Y8M
jshell> "WAR OF 1812 TIMEFRAME: " + period;
$34 ==> "WAR OF 1812 TIMEFRAME: P2Y8M"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment