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;
/*ja  v a  2s .c o 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