DateFormat in Java

String a= "22-Серпня-2015 22:25:36 ";
Locale loc_ukr = new Locale("uk", "UA");
DateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss",loc_ukr);

Date date = format.parse(a);
System.out.print(date);

How do I display the date so that the console displays in Ukrainian?

Author: diralik, 2017-09-06

2 answers

Using the Java 8 Date and Time API:

public static void main(String[] args) {
    String a = "22-Серпня-2015 22:25:36";
    Locale loc_ukr = new Locale("uk", "UA");

    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMMM-yyyy HH:mm:ss", loc_ukr);
    System.out.println(dtf.parse(a.toLowerCase()).toString());
}

Result:

{},ISO resolved to 2015-08-22T22:25:36

Don't forget that pattern is case-sensitive and won't parse without a.toLowerCase ().

 4
Author: DaysLikeThis, 2017-09-07 05:06:01

IMHO, you need to create your own Locale, and dig into DateFormatSymbols, because this class gives information about the format of numbers, dates, etc.

The Locale class simply stores information about the Locale (country, language).

 -1
Author: Бог, 2017-09-06 21:12:18