English English

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/ard-site/templates/ardsite/library/Designer/Content/SingleArticle.php on line 198

Formatting LocalDate object as a string

LocalDate is a class with many features which can be used to create date and time in Java. It was introduced in Java 8. The class SimpleDateFormat cannot be used with LocalDate.

LocalDate object can be formatted with the class DateTimeFormatter. First create a LocalDate object with the current date.

LocalDate localDateObject = LocalDate.now();

Then create a DateTimeFormatter object to format the date as you wish.

DateTimeFormatter dtformat = DateTimeFormatter.ofPattern("dd.MM.yyyy");

"MM" stands for month. But "mm" stands for minute.

 

The DateTimeFormatter object can be called through this method directly.

String dateString = localDateObject.format(dtformat);



More information about the class "DateTimeFormatter":
http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

 

 

We use cookies on our website. They are essential for the operation of the site
Ok