Calendar class
In this chapter you will learn:
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:
- Get month, date and year from Calendar
- How to get Get hour, minute, second out of a Calendar
- Getting current week of the month
- Getting current week of the year
- Convert month index to month name
- Get the name for day of a week
Home » Java Tutorial » Date, Time, Calendar, TimeZone