Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Gregorian Calendar in Java
GregorianCalendar is a hybrid calendar that supports both the Julian and Gregorian calendar systems with the support of a single discontinuity, which corresponds by default to the Gregorian date when the Gregorian calendar was instituted.
The java.util.GregorianCalendar class in Java is a concrete subclass of Calendar and provides the standard calendar system used by most of the world.
Import the following package to work with GregorianCalendar class.
import java.util.GregorianCalendar;
The following are the constructors.
| Sr.No. | Constructor & Description |
|---|---|
| 1 |
GregorianCalendar() This constructs a default GregorianCalendar using the current time in the default time zone with the default locale. |
| 2 |
GregorianCalendar(int year, int month, int dayOfMonth) This constructs a GregorianCalendar with the given date set in the default time zone with the default locale. |
| 3 | GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute) This constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale. |
| 4 |
GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second) This constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale. |
| 5 |
GregorianCalendar(Locale aLocale) This constructs a GregorianCalendar based on the current time in the default time zone with the given locale. |
| 6 |
GregorianCalendar(TimeZone zone) This constructs a GregorianCalendar based on the current time in the given time zone with the default locale. |
| 7 |
GregorianCalendar(TimeZone zone, Locale aLocale) This constructs a GregorianCalendar based on the current time in the given time zone with the given locale. |
Example
import java.util.GregorianCalendar;
public class Demo {
public static void main(String[] args) {
GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
System.out.println("" + cal.getTime());
}
}
Output
Mon Nov 19 15:57:40 UTC 2018
Advertisements