Get field value from Calendar

TypeMethodSummary
intget(int field)Returns the value of the given calendar field.
intgetActualMaximum(int field)Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.
intgetActualMinimum(int field)Returns the minimum value that the specified calendar field could have, given the time value of this Calendar.
intgetFirstDayOfWeek()Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.
intgetMinimalDaysInFirstWeek()Gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, this method returns 1.
DategetTime()Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").
longgetTimeInMillis()Returns this Calendar's time value in milliseconds.
TimeZonegetTimeZone()Gets the time zone.

Display Day of Week


import java.util.Calendar;

public class Main {
  public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-"
        + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR));

    String[] strDays = new String[] { "Sunday", "Monday", "Tuesday",
        "Wednesday", "Thusday", "Friday", "Saturday" };
    System.out.println("Current day is : "
        + strDays[now.get(Calendar.DAY_OF_WEEK) - 1]);
  }
}

The output:


Current date : 10-30-2010
Current day is : Saturday
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.