Example usage for java.util Locale getDefault

List of usage examples for java.util Locale getDefault

Introduction

In this page you can find the example usage for java.util Locale getDefault.

Prototype

public static Locale getDefault(Locale.Category category) 

Source Link

Document

Gets the current value of the default locale for the specified Category for this instance of the Java Virtual Machine.

Usage

From source file:Main.java

/**
 * Converts a LocalDate (ISO) value to a ChronoLocalDate date using the
 * provided Chronology, and then formats the ChronoLocalDate to a String using
 * a DateTimeFormatter with a SHORT pattern based on the Chronology and the
 * current Locale.//  w w w  .j ava 2 s.co m
 *
 * @param localDate
 *          - the ISO date to convert and format.
 * @param chrono
 *          - an optional Chronology. If null, then IsoChronology is used.
 */
public static String toString(LocalDate localDate, Chronology chrono) {
    if (localDate != null) {
        Locale locale = Locale.getDefault(Locale.Category.FORMAT);
        ChronoLocalDate cDate;
        if (chrono == null) {
            chrono = IsoChronology.INSTANCE;
        }
        try {
            cDate = chrono.date(localDate);
        } catch (DateTimeException ex) {
            System.err.println(ex);
            chrono = IsoChronology.INSTANCE;
            cDate = localDate;
        }
        String pattern = "M/d/yyyy GGGGG";
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern);
        return dateFormatter.format(cDate);
    } else {
        return "";
    }
}