Java Calendar getInstance() 方法

2024 年 11 月 3 日 | 阅读 3 分钟

java.util.Calendar 类的 getInstance() 方法是一个静态方法。此方法用于 Calendar 对象,以获取根据 Java 运行时环境设置的当前时区的日历实例。

语法

参数

Locale 和 TimeZone 作为参数传递。

返回值

返回 Calendar 。

抛出

不抛出异常。

示例 1

输出

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

示例 2

输出

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

示例 3

输出

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

示例 4

输出

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

示例 5

输出

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

示例 6

输出

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