1 // DateTimeFormatterTest.java
2 import java.time.LocalDate;
3 import java.time.format.DateTimeFormatter;
4 import java.time.format.FormatStyle;
5 import java.util.Locale;
6
7 /** 8 * DateTimeFormatterTest zeigt den Umgang mit der Klasse DateTimeFormatter. 9 * Beispielprogramm zur Programmiertechnik 1, Teil 5. 10 * @author H.Drachenfels 11 * @version 24.5.2017 12 */
13 public final class DateTimeFormatterTest {
14 private DateTimeFormatterTest() { }
15
16 /** 17 * main ist der Startpunkt des Programms. 18 * @param args wird nicht verwnedet 19 */
20 public static void main(String[] args) {
21
22 DateTimeFormatter[] datumsFormate = {
23 DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT),
24 DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM),
25 DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG),
26 DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL),
27
28 DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
29 .withLocale(Locale.GERMAN),
30 DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
31 .withLocale(Locale.GERMAN),
32 DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)
33 .withLocale(Locale.GERMAN),
34 DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
35 .withLocale(Locale.GERMAN),
36
37 DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
38 .withLocale(Locale.ENGLISH),
39 DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
40 .withLocale(Locale.ENGLISH),
41 DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)
42 .withLocale(Locale.ENGLISH),
43 DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
44 .withLocale(Locale.ENGLISH),
45
46 DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
47 .withLocale(Locale.UK),
48 DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
49 .withLocale(Locale.UK),
50 DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)
51 .withLocale(Locale.UK),
52 DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
53 .withLocale(Locale.UK),
54 };
55
56 LocalDate heute = LocalDate.now();
57
58 for (DateTimeFormatter f : datumsFormate) {
59 String s = f.format(heute);
60 System.out.println(s);
61 }
62 }
63 }
64