Display Day of Week using Calendar - Java Date Time

Java examples for Date Time:Calendar

Description

Display Day of Week using Calendar

Demo Code


import java.util.Calendar;
 
public class Main {
 
  public static void main(String[] args) {
 
    //create Calendar instance
    Calendar now = Calendar.getInstance();
   /*from   ww  w. j a  va2s  .  c o  m*/
    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1)
                        + "-"
                        + now.get(Calendar.DATE)
                        + "-"
                        + now.get(Calendar.YEAR));
   
    //create an array of days
    String[] strDays = new String[]{
                      "Sunday",
                      "Monday",
                      "Tuesday",
                      "Wednesday",
                      "Thusday",
                      "Friday",
                      "Saturday"
                    };
   
    //Day_OF_WEEK starts from 1 while array index starts from 0      
    System.out.println("Current day is : " +
              strDays[now.get(Calendar.DAY_OF_WEEK) - 1]
              );
   
 
  }
 
}

Result


Related Tutorials