How do I get a formatted date for a specific pattern and locale?

If you want to change formatting styles provided by DateFormat, you can uses SimpleDateFormat class. The SimpleDateFormat class is locale-sensitive.

If you instantiate SimpleDateFormat without a Locale parameter, it will format the date and time according to the default Locale. Both the pattern and the Locale determine the format. For the same pattern, SimpleDateFormat may format a date and time differently if the Locale varies.

package org.kodejava.example.text;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class SimpleDateFormatChangeLocalePattern {
    public static void main(String[] args) {
        String pattern = "dd-MMM-yyyy";
        Date today = new Date();

        // Gets a formatted date according to the given pattern.
        // Here only the pattern is passed as argument of the
        // SimpleDateFormat constructor, so it will format the
        // date according to the default Locale.
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        String local = sdf.format(today);
        System.out.println("Date in default locale: " + local);

        Locale[] locales = {
            Locale.CANADA,
            Locale.FRANCE,
            Locale.GERMANY,
            Locale.US,
            Locale.JAPAN
        };

        for (Locale locale : locales) {
            // Format a date according to the given pattern for each locale.
            sdf = new SimpleDateFormat(pattern, locale);
            String after = sdf.format(today);
            System.out.println(locale.getDisplayCountry() + " | format: " + after);
        }
    }
}

Here are the variety of output produces when formatting a date in the same date pattern but varies in Locale

Date in default locale: 12-Apr-2018
Canada | format: 12-Apr-2018
France | format: 12-avr.-2018
Germany | format: 12-Apr-2018
United States | format: 12-Apr-2018
Japan | format: 12-4-2018

How do I get default date and time format for a defined country?

The DateFormat class allows you to format dates and times with predefined styles in a locale-sensitive manner. Formatting dates or times with the DateFormat class is a two-step process.

First, you create a formatter with the getDateInstance() method for formatting date or getTimeInstance() method for formatting time or getDateTimeInstance() when you want formatting both date and time.

Second, you invoke the format method, which returns a String containing the formatted date. The following example formats today’s date and time by calling those two methods.

package org.kodejava.example.text;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class LocaleDateTime {
    public static void main(String[] args) {
        Locale[] locales = {Locale.CANADA, Locale.FRANCE, Locale.GERMANY,
            Locale.US, Locale.JAPAN};

        Date today = new Date();
        for (Locale locale : locales) {
            StringBuilder sb = new StringBuilder();
            sb.append(locale.getDisplayCountry())
                .append(System.lineSeparator());
            sb.append("--------------------------------")
                .append(System.lineSeparator());

            // Gets a DateFormat instance for the specified locale
            // and format a date object by calling the format
            // method.
            DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
            String date = df.format(today);
            sb.append("Default date format: ").append(date)
                .append(System.lineSeparator());

            // Gets a DateFormat instance for the specified locale
            // and format a time information by calling the format
            // method.
            DateFormat tf = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
            String time = tf.format(today.getTime());
            sb.append("Default time format: ").append(time)
                .append(System.lineSeparator());

            System.out.println(sb.toString());
        }

        // Gets date and time formatted value for Italy locale using
        // To display a date and time in the same String, create the
        // formatter with the getDateTimeInstance method.
        // The first parameter is the date style, and the second is
        // the time style. The third parameter is the Locale
        DateFormat dtf = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
            DateFormat.DEFAULT, Locale.ITALY);
        String datetime = dtf.format(today);

        System.out.println("date time format in " +
            Locale.ITALY.getDisplayCountry() + ": " + datetime);
    }
}

Here are the produces output:

Canada
--------------------------------
Default date format: 10-Apr-2018
Default time format: 10:18:11 PM

France
--------------------------------
Default date format: 10 avr. 2018
Default time format: 22:18:11

Germany
--------------------------------
Default date format: 10.04.2018
Default time format: 22:18:11

United States
--------------------------------
Default date format: Apr 10, 2018
Default time format: 10:18:11 PM

Japan
--------------------------------
Default date format: 2018/04/10
Default time format: 22:18:11

date time format in Italy: 10-apr-2018 22.18.11