Get localized short day-in-week name in Java



Use the ‘a’ date conversion character to display short day-in-week.

System.out.printf("Localized short day name = %ta/%Ta
", d, d);

Above, d is a date object −

Date d = new Date();

The following is an example −

Example

 Live Demo

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Demo {
   public static void main(String[] args) throws Exception {
      Date d = new Date();
      DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
      String format = dateFormat.format(d);
      System.out.println("Current date and time = " + format);
      System.out.printf("Localized day name = %tA/%TA
", d, d); System.out.printf("Localized short day name = %ta/%Ta
", d, d); } }

Output

Current date and time = 26/11/2018 11:46:45 AM
Localized day name = Monday/MONDAY
Localized short day name = Mon/MON
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements