This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> import java.util.ArrayList; | |
| jshell> import java.time.format.DateTimeFormatter; ^ | |
| jshell> ArrayList<DateTimeFormatter> ldtFormattersList = new ArrayList<>(); | |
| ldtFormattersList ==> [] | |
| jshell> ldtFormattersList.add(DateTimeFormatter.BASIC_ISO_DATE); | |
| $57 ==> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> import static java.time.format.DateTimeFormatter.*; | |
| jshell> ld.format(ISO_WEEK_DATE); | |
| $43 ==> "2019-W17-6" | |
| jshell> import java.time.OffsetDateTime; | |
| jshell> OffsetDateTime odt = OffsetDateTime.now(); | |
| odt ==> 2019-04-27T16:22:54.724099-05:00 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> Period p1 = Period.parse("P0Y13M"); | |
| p1 ==> P13M | |
| jshell> "Original: " + p1 + " Normalized: " + p1.normalized(); | |
| $36 ==> "Original: P13M Normalized: P1Y1M" | |
| jshell> Period p2 = Period.parse("P2Y-1M"); | |
| p2 ==> P2Y-1M | |
| jshell> "Original: " + p2 + " Normalized: " + p2.normalized(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> Period p1 = Period.parse("P10D").minusDays(10); | |
| p1 ==> P0D | |
| jshell> "Is zero: " + p1.isZero(); | |
| $24 ==> "Is zero: true" | |
| jshell> // Period equals negative value | |
| jshell> Period p2 = Period.parse("P2019M"); | |
| p2 ==> P2019M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> Period period = Period.of(5, 2, 1); | |
| period ==> P5Y2M1D | |
| jshell> period = period.plusYears(10); | |
| period ==> P15Y2M1D | |
| jshell> period = period.plusMonths(10); | |
| period ==> P15Y12M1D | |
| jshell> period = period.plusDays(15); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> Period P1 = Period.ofYears(1); // 1 year | |
| P1 ==> P1Y | |
| jshell> Period P2 = Period.ofMonths(12) // 1 year | |
| P2 ==> P12M | |
| jshell> Period P3 = Period.ofWeeks(52) // 1 year | |
| P3 ==> P364D | |
| jshell> Period P4 = Period.ofDays(366) // 1 year (leap) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> import java.util.Calendar; | |
| jshell> import java.time.Instant; | |
| jshell> Calendar calendar = Calendar.getInstance(); | |
| calendar ==> java.util.GregorianCalendar[time=1556074159985,ar ... 600000,DST_OFFSET=3600000] | |
| jshell> Instant instant = calendar.toInstant(); | |
| instant ==> 2019-04-24T02:49:19.985Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jshell> LocalDateTime ldt1 = LocalDateTime.now(); | |
| ldt1 ==> 2019-04-23T21:41:59.084165 | |
| jshell> LocalDateTime ldt2 = LocalDateTime.parse("2019-01-01T12:00:00"); | |
| ldt2 ==> 2019-01-01T12:00 | |
| jshell> LocalDateTime ldt3 = LocalDateTime.of(2019, 1, 1, 12, 0); | |
| ldt3 ==> 2019-01-01T12:00 | |
| jshell> LocalDateTime ldt4 = LocalDateTime.of(2019, Month.JANUARY, 1, 12, 0); |