Display date in different formats with the LocalDate class

Since Java 8 a new date API is available. This example shows how to display todays date in different formats using this new API. The LocalDate class has a method called now() to get the current date. The LocalDate class then have methods to get day, month and year in different formats (either as number, text, short text etc). This is accomplished with the TextStyle class.
In the example we use String.format() to output the data in the format we want. The %d means we want to output a digit (integer etc.) and the %s means we want to output a string.

The output format from the code above is:

Search for more Java info on this site here:
Custom Search

Please type any questions here.