Change date formatting symbols in Java

Java 8Object Oriented ProgrammingProgramming

For date formatting symbols, use the DateFormatSymbols class.

Firstly, set weekdays using a string array

String[] weekDays2 = { "", "monday", "tuesday", "wednesday", "thursday", "friday","saturday", "sunday" };

Now, set short week days with

DateFormatSymbols mySymbols = new DateFormatSymbols();
mySymbols.setShortWeekdays(weekDays2);

Get the date −

dateFormat = new SimpleDateFormat("EEEE, dd MMM yyyy", mySymbols);
System.out.println(dateFormat.format(new Date()));

The following is an example −

Example

 Live Demo

import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      String[] weekDays1 = { "", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
      String[] weekDays2 = { "", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
      DateFormatSymbols mySymbols = new DateFormatSymbols();
      mySymbols.setWeekdays(weekDays1);
      mySymbols.setShortWeekdays(weekDays2);
      DateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy", mySymbols);
      System.out.println(dateFormat.format(new Date()));
      dateFormat = new SimpleDateFormat("EEEE, dd MMM yyyy", mySymbols);
      System.out.println(dateFormat.format(new Date()));
   }
}

Output

friday, 22 Nov 2018
Friday, 22 Nov 2018
raja
Published on 19-Dec-2018 09:55:26
Advertisements