Skip to content

Commit 7f6df18

Browse files
committed
BAEL-2258 Guide to DateTimeFormatter. Predefined formatters tests added
1 parent f9065d2 commit 7f6df18

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

core-java-8/src/test/java/com/baeldung/internationalization/DateTimeFormatterUnitTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void givenDateTimeAndTimeZone_whenFormatWithDifferentLocales_thenGettingL
4848
}
4949

5050
@Test
51-
public void shoulPrintFormattedDate() {
51+
public void shouldPrintFormattedDate() {
5252
String europeanDatePattern = "dd.MM.yyyy";
5353
DateTimeFormatter europeanDateFormatter = DateTimeFormatter.ofPattern(europeanDatePattern);
5454
LocalDate summerDay = LocalDate.of(2016, 7, 31);
@@ -112,4 +112,11 @@ public void shouldPrintStyledDateTime() {
112112
Assert.assertEquals("Aug 23, 2016 1:12:45 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
113113
Assert.assertEquals("8/23/16 1:12 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
114114
}
115+
116+
@Test
117+
public void shouldPrintFormattedDateTimeWithPredefined() {
118+
Assert.assertEquals("2018-03-09", DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDate.of(2018, 3, 9)));
119+
Assert.assertEquals("2018-03-09-03:00", DateTimeFormatter.ISO_OFFSET_DATE.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3"))));
120+
Assert.assertEquals("Fri, 9 Mar 2018 00:00:00 -0300", DateTimeFormatter.RFC_1123_DATE_TIME.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3"))));
121+
}
115122
}

0 commit comments

Comments
 (0)