While working with java.util.Date, we made use of java.text.SimpleDateFormat to format the date into different text representations and vice versa. Formatting a date means, given a date or a time object representing it in different formats, such as the following:
- 23 Jun 2018
- 23-08-2018
- 2018-08-23
- 23 Jun 2018 11:03:33 AM
These formats are controlled by format strings, such as the following:
- dd MMM yyyy
- dd-MM-yyyy
- yyyy-MM-DD
- dd MMM yyyy hh:mm:ss
In this recipe, we will look at java.time.format.DateTimeFormatter to format the date and time instances in the new date and time API and also look at the most commonly used pattern letters.