[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese

Development environment

-Host OS: Windows10 Home insider build preview ・ Guest OS: WSL2 Ubuntu18.04 LTS ・ VScode ver1.44.2 · Java openjdk11

problem


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).

Solution

① 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.

Reference material

Locale (Java Platform SE 7) DateTimeFormatter (Java Platform SE 8) LocalDate (Java Platform SE 8)

Recommended Posts

[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese
How to derive the last day of the month in Java
How to get today's day of the week
[Ruby] Code to display the day of the week
[Rails] How to display the list of posts by category
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
[Java1.8 +] Get the date of the next x day of the week with LocalDate
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
How to get the date in java
How to display error messages in Japanese
How to find the total number of pages when paging in Java
How to get the absolute path of a directory running in Java
Display Japanese calendar and days of the week using java8 standard class
I want to output the day of the week
How to display a web page in Java
How to display the result of form input
[Java] How to get the authority of the folder
How to display the amount of disk used by Docker container for each container
[Java] How to get the URL of the transition source
[Ubuntu 20.04] Display the day of the week on the date / clock
How to set the display time to Japan time in Rails
[Java] How to get the maximum value of HashMap
Summary of how to implement default arguments in Java
[Rails] How to display an image in the view
[Java] Integer information of characters in a text file acquired by the read () method
[Java] How to get the key and value stored in Map by iterative processing
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
[Introduction to Java] List of things that got caught by the 14th day of programming
Summary of how to use the proxy set in IE when connecting with Java
[Java] How to display Wingdings
How to get the class name / method name running in Java
Was done in the base year of the Java calendar week
How to display the select field of time_select every 30 minutes
How to dynamically change the column name acquired by MyBatis
[Ruby] Display today's day of the week using Date class
How to implement one-line display of TextView in Android development
How to switch Java in the OpenJDK era on Mac
[Rails] How to display information stored in the database in view
Considering the adoption of Java language in the Reiwa era ~ How to choose a safe SDK
[Rails] How to write in Japanese
How to learn JAVA in 7 days
How to make a key pair of ecdsa in a format that can be read by Java
[Rails] How to omit the display of the character string of the link_to method
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
How to use classes in Java?
How to name variables in Java
How to solve the unknown error when using slf4j in Java
Let's create a TODO application in Java 5 Switch the display of TODO
I tried to assemble from 0 while considering the table design of the day / week / month / overall ranking display function in terms of performance.
How to check for the contents of a java fixed-length string
How to concatenate strings in java
[Rails] How to display the list of posts by category
How to set the indent to 2 single-byte spaces in the JAXB implementation of the JDK
The story of forgetting to close a file in Java and failing
[Java] How to receive numerical data separated by spaces in standard input
How to switch the display of the header menu for each transition page
How to change the maximum and maximum number of POST data in Spark
How to find out the Java version of a compiled class file
[Java] How to get to the front of a specific string using the String class
How to get the value after "_" in Windows batch like Java -version