Java LocalDate to String dateToString(LocalDate date)

Here you can find the source of dateToString(LocalDate date)

Description

date To String

License

Open Source License

Declaration

public static String dateToString(LocalDate date) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.LocalDate;

import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    private static final String SHORT_PATTERN_EN = "yyyy-MM-dd";
    private static final String SHORT_PATTERN_FR = "dd/MM/yyyy";

    /**/* w ww . j  ava2s. c o m*/
     * @param date The date to format
     * @return A date given following {@link #SHORT_PATTERN_EN} pattern  
     */
    public static String dateToString(LocalDate date, Locale locale) {
        return getShortFormatter(locale).format(date);
    }

    public static String dateToString(LocalDate date) {
        return dateToString(date, null);
    }

    private static DateTimeFormatter getShortFormatter(Locale locale) {
        String pattern = SHORT_PATTERN_EN;
        if (Locale.FRANCE.equals(locale))
            pattern = SHORT_PATTERN_FR;
        return DateTimeFormatter.ofPattern(pattern);
    }
}

Related

  1. dateToFullString(LocalDate date)
  2. localDate2Str(LocalDate localDate)
  3. localDateToString(LocalDate date)
  4. toDateString(LocalDate date, String pattern)
  5. toString(LocalDate d)