Java Calendar getInstance() Method

The getInstance() method of java.util.Calendar class is a Static method. This method is used with calendar object to get the instance of calendar according to current time zone set by java Runtime environment.

Syntax

Parameter

Locale and TimeZone are passed as parameters.

Returns

Returns Calendar .

Throws

Does not throw exception.

Example 1

Output:

mycal1 :Sat Aug 04 14:54:57 PDT 2018
mycal2 :Wed Oct 23 14:54:57 PDT 1996
both the instance of calendat are not equal

Example 2

Output:

mycal1 :Sat Aug 04 15:01:45 PDT 2018
mycal2 :Sat Aug 04 15:01:45 PDT 2018
both the instance of calendat are not equal
mycal1 :Thu Jan 01 00:00:00 PST 1970
mycal2 :Thu Jan 01 00:00:00 PST 1970

Example 3

Output:

mycal1 :Sat Aug 04 23:23:00 PDT 2018
mycal2 :Wed Oct 23 23:23:00 PDT 1996
both the instance of calendat are not equal

Example 4

Output:

mycal1 :Sat Aug 04 23:25:44 PDT 2018
mycal2 :Sat Aug 04 23:25:44 PDT 2018
both the instance of calendat are not equal
mycal1 :Thu Jan 01 00:00:00 PST 1970
mycal2 :Thu Jan 01 00:00:00 PST 1970

Example 5

Output:

mycal1 :Sun Aug 05 00:00:08 PDT 2018
mycal2 :Sun Aug 05 00:00:08 PDT 2018
both the instance of calendar are not equal
mycal1 :Wed Dec 31 16:00:00 PST 1969
mycal2 :Wed Dec 31 16:00:00 PST 1969

Example 6

Output:

mycal1 :Sun Aug 05 00:01:38 PDT 2018
mycal2 :Wed Oct 23 00:01:38 PDT 1996
both the instance of calendar are not equal