Formatting day of week using SimpleDateFormat - Java Date Time

Java examples for Date Time:SimpleDateFormat

Description

Formatting day of week using SimpleDateFormat

Demo Code


import java.text.SimpleDateFormat;
import java.util.Date;
 
public class Main {
 
  public static void main(String[] args) {
     Date date = new Date();
   // w  w  w.  j  a v a 2 s  . c  o m
     //formatting day of week in E format like Sun, Mon etc.
     String strDateFormat = "E";
     SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
     
     System.out.println("Current day of week in E format : " + sdf.format(date));
     
     //formatting day of week in EEEE format like Sunday, Monday etc.
     strDateFormat = "EEEE";
     sdf = new SimpleDateFormat(strDateFormat);
     System.out.println("Current day of week in EEEE format : " + sdf.format(date));
  }
}

Result


Related Tutorials