Java SimpleDateFormat format day of week as "Sun", "Sunday"

Description

Java SimpleDateFormat format day of week as "Sun", "Sunday"

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

  public static void main(String[] args) {
    Date date = new Date();

    // formatting day of week in E format like Sun, Mon etc.

    SimpleDateFormat sdf = new SimpleDateFormat("E");

    System.out.println("Current day of week in E format : " + sdf.format(date));

    // formatting day of week in EEEE format like Sunday, Monday etc.
    sdf = new SimpleDateFormat("EEEE");
    System.out.println("Current day of week in EEEE format : " + sdf.format(date));
  }/*from w  w w. j  a  v a  2s  . c  o  m*/
}



PreviousNext

Related