![java string format java string format](https://i.ytimg.com/vi/Va7zaaZVMjo/maxresdefault.jpg)
The LocalDate class represents the date without time in ISO-8601 format (yyyy-MM-dd). Let us look at the LocalDate and LocalDateTime examples below to see how it works. DateTimeFormatter is used to specify a pattern for formatting and parsing date-time objects in Java 8 new date and time API. The format() method returns the formatted date string. Java 8 new date and time API provides format() method that accepts an instance of DateTimeFormatter to format this date using the specified format: format ( DateTimeFormatter formatter ) All the classes in the new date and time API use ISO-8601 format to represent dates and times. Java 8 new API is thread-safe, easier-to-use, and provides a lot of utility methods for date and time operations. Java 8 Date & Time APIĪ new date and time API was introduced in Java 8 (classes in java.time.* package) to fix the flaws of old and API. Similarly, you may want to convert a date from MM/dd/yyyy to dd-MMM-yyyy or any other format of your choice. For instance, you may have a date like T15:23 and you want to change its format to Decem03:23 PM. There are many scenarios where you want to convert an instance of date to a more human-readable format. In this article, you'll learn to change the format of a given date or a string to a new format using both Java 8 new date and time API and legacy API. In my previous article, we have already looked at different ways to convert a string to a date using Java 8 new date and time API as well as legacy Date and Calendar API.
![java string format java string format](https://coderanch.com/t/618646/a/4589/parseDateError.png)
![java string format java string format](https://2.bp.blogspot.com/-dxm10Skmq_c/VDi7Mw-E-KI/AAAAAAAACBk/7VXhTlcHnuM/w1200-h630-p-k-no-nu/How%2Bto%2Badd%2Bleading%2Bzero%2Bin%2Bnumeric%2BStirng%2Bjava.png)
One of the most common tasks in Java programming is to format a date to a string or convert a string back to a date.