ofPatternの中のパターン文字ではない値は''で囲う
Locale.Category.DISPLAYは何が変わるのか不明
Locale.Category.CATEGORYは通貨日付に影響
public class SampleProject {
public static void main(String args[]) {
method();
Locale.setDefault(Locale.US);
method();
Locale.setDefault(Locale.Category.DISPLAY,Locale.JAPAN);
method();
Locale.setDefault(Locale.Category.FORMAT,Locale.JAPAN);
method();
}
static void method() {
System.out.println("----------------");
LocalDateTime ld = LocalDateTime.now();
System.out.println(DateTimeFormatter.BASIC_ISO_DATE.format(ld));
System.out.println(DateTimeFormatter.ISO_DATE.format(ld));
System.out.println(DateTimeFormatter.ISO_TIME.format(ld));
System.out.println(DateTimeFormatter.ISO_DATE_TIME.format(ld));
DateTimeFormatter f1 = DateTimeFormatter.ofPattern("yyyyねんMMがつddひe");
DateTimeFormatter f11 = DateTimeFormatter.ofPattern("yyyyねんMMMがつddひee");
DateTimeFormatter f12 = DateTimeFormatter.ofPattern("'eee'yyyyねんMMMMがつddひeee");
DateTimeFormatter f15 = DateTimeFormatter.ofPattern("yyyy'ねん'MMMM'がつ'dd'ひ'eeee");
DateTimeFormatter f13 = DateTimeFormatter.ofPattern("yyyyねんMMMMMがつddひeeeee");
// DateTimeFormatter f14 = DateTimeFormatter.ofPattern("yyyyねんMMMMMMがつddひeeeeee"); //err too many M too many e
DateTimeFormatter f2 = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
DateTimeFormatter f3 = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
DateTimeFormatter f4 = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
DateTimeFormatter f5 = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
System.out.println(f1.format(ld));
System.out.println(f11.format(ld));
System.out.println(f12.format(ld));
System.out.println(f15.format(ld));
System.out.println(f13.format(ld));
System.out.println(f2.format(ld));
System.out.println(f3.format(ld));
System.out.println(f4.format(ld));
System.out.println(f5.format(ld));
}
}
----------------
20230305
2023-03-05
12:27:21.5919478
2023-03-05T12:27:21.5919478
2023ねん03がつ05ひ1
2023ねんMarがつ05ひ01
eee2023ねんMarchがつ05ひSun
2023ねんMarchがつ05ひSunday
2023ねんMがつ05ひS
Sunday, March 5, 2023
March 5, 2023
Mar 5, 2023
3/5/23
----------------
20230305
2023-03-05
12:27:21.7482069
2023-03-05T12:27:21.7482069
2023ねん03がつ05ひ1
2023ねんMarがつ05ひ01
eee2023ねんMarchがつ05ひSun
2023ねんMarchがつ05ひSunday
2023ねんMがつ05ひS
Sunday, March 5, 2023
March 5, 2023
Mar 5, 2023
3/5/23
----------------
20230305
2023-03-05
12:27:21.7482069
2023-03-05T12:27:21.7482069
2023ねん03がつ05ひ1
2023ねんMarがつ05ひ01
eee2023ねんMarchがつ05ひSun
2023ねんMarchがつ05ひSunday
2023ねんMがつ05ひS
Sunday, March 5, 2023
March 5, 2023
Mar 5, 2023
3/5/23
----------------
20230305
2023-03-05
12:27:21.7482069
2023-03-05T12:27:21.7482069
2023ねん03がつ05ひ1
2023ねん3月がつ05ひ01
eee2023ねん3月がつ05ひ日
2023ねん3月がつ05ひ日曜日
2023ねん3がつ05ひ日
2023年3月5日日曜日
2023年3月5日
2023/03/05
2023/03/05