-Host OS: Windows10 Home insider build preview ・ Guest OS: WSL2 Ubuntu18.04 LTS ・ VScode ver1.44.2 · Java openjdk11
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Time {
public static void main(String[] args) {
LocalDate localDate = LocalDate.of(2020, 6, 3).plusMonths(1).plusDays(24);
DateTimeFormatter formmater = DateTimeFormatter.ofPattern("yyyy year MM month dd day(E)");
String format = localDate.format(formmater);
System.out.println(format);
}
}
The result of compiling and executing the above code
July 27, 2020(Mon)
And the part of the day of the week is output in English. I want to display (Mon) instead of (Mon).
① Import java.util.Locale (2) Pass Locale.JAPANESE as the second argument of the ofPattern method and specify the Japanese notation.
Check with the actual code
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
//Change part
import java.util.Locale;
public class Time {
public static void main(String[] args) {
LocalDate localDate = LocalDate.of(2020, 6, 3).plusMonths(1).plusDays(24);
//Change part
DateTimeFormatter formmater = DateTimeFormatter.ofPattern("yyyy year MM month dd day(E)", Locale.JAPANESE);
String format = localDate.format(formmater);
System.out.println(format);
}
}
The output result is ...
July 27, 2020(Month)
I was able to safely change the day of the week to Japanese notation.
Locale (Java Platform SE 7) DateTimeFormatter (Java Platform SE 8) LocalDate (Java Platform SE 8)
Recommended Posts