Calendar class

In this chapter you will learn:

  1. How to create Calendar class

Create Calendar class

Calendar class is an abstract class that provides methods for date and time related operation.

The following methods create Calendar class instance.

  • static Calendar getInstance()
    Gets a calendar using the default time zone and locale.
  • static Calendar getInstance(Locale aLocale)
    Gets a calendar using the default time zone and specified locale.
  • static Calendar getInstance(TimeZone zone)
    Gets a calendar using the specified time zone and default locale.
  • static Calendar getInstance(TimeZone zone, Locale aLocale)
    Gets a calendar with the specified time zone and locale.

The following code creates a Calendar object and output its value.

import java.util.Calendar;
//from  j a v  a2s.co m
public class Main {
  public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    
    System.out.println(now);
    
  }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. Get month, date and year from Calendar
  2. How to get Get hour, minute, second out of a Calendar
  3. Getting current week of the month
  4. Getting current week of the year
  5. Convert month index to month name
  6. Get the name for day of a week
Home » Java Tutorial » Date, Time, Calendar, TimeZone

Date

    Date class
    Date comparison
    Converting date value
    DateFormat class
    Format time
    DateFormat and Locale
    Convert String to Date

Calendar

    Calendar class
    Calendar date time getter
    Calendar set hour,minute,second
    Calendar calculation
    Calendar comparison
    Calendar properties
    GregorianCalendar

TimeZone

    TimeZone
    TimeZone ID and display name
    TimeZone daylight saving

DateFormat

    DateFormat class
    Format time
    DateFormat and Locale
    Convert String to Date
    SimpleDateFormat
    Parse date string into Date object
    SimpleDateFormat day format
    SimpleDateFormat Hour Time format
    SimpleDateFormat format minute
    SimpleDateFormat to format month
    SimpleDateFormat to format second value
    SimpleDateFormat to format TimeZone
    SimpleDateFormat to format year
    SimpleDateFormat to combine formatting flags