Returns the given date as a well formatted String using DateTimeFormatter. - Java java.time

Java examples for java.time:Format

Description

Returns the given date as a well formatted String using DateTimeFormatter.

Demo Code


import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class Main{
    /** The date formatter. */
        private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter
                .ofPattern(DATE_PATTERN);
    /**//from   ww  w.j av a 2  s. c  o m
         * Returns the given date as a well formatted String. The above defined 
         * {@link DateUtil#DATE_PATTERN} is used.
         * 
         * @param date the date to be returned as a string
         * @return formatted string
         */
        public static String format(LocalDate date) {
            if (date == null) {
                return null;
            }
            return DATE_FORMATTER.format(date);
        }
}

Related Tutorials