package org.kodejava.text;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class ChangeDateFormatSymbols {
public static void main(String[] args) {
Locale id = new Locale("in", "ID");
String pattern = "EEEE, dd MMM yyyy";
Date today = new Date();
// Gets formatted date specify by the given pattern for
// Indonesian Locale no changes for default date format
// is applied here.
SimpleDateFormat sdf = new SimpleDateFormat(pattern, id);
String before = sdf.format(today);
System.out.println("Before format change: " + before);
// Create a DateFormatSymbols object for Indonesian locale.
DateFormatSymbols dfs = new DateFormatSymbols(id);
// Gets String array of default format of weekdays.
String[] days = dfs.getWeekdays();
String[] newDays = new String[days.length];
for (int i = 0; i < days.length; i++) {
// For each day, apply toUpperCase() method to
// capitalized it.
newDays[i] = days[i].toUpperCase();
}
// Set String array of weekdays.
dfs.setWeekdays(newDays);
// Gets String array of default format of short months.
String[] shortMonths = dfs.getShortMonths();
String[] months = new String[shortMonths.length];
for (int j = 0; j < shortMonths.length; j++) {
// For each short month, apply toUpperCase() method
// to capitalized it.
months[j] = shortMonths[j].toUpperCase();
}
// Set String array of short months.
dfs.setShortMonths(months);
// Create a SimpleDateFormat object by given pattern and
// symbol and then format the date object as String.
sdf = new SimpleDateFormat(pattern, dfs);
String after = sdf.format(today);
System.out.println("After change format : " + after);
}
}
Here are the output of our program:
Before format change: Selasa, 19 Okt 2021
After change format : SELASA, 19 OKT 2021
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024