java.util下的Calendar类

本文深入解析了Java中Calendar API的使用方法,包括日期和时间的获取、设置、加减操作,以及如何比较不同Calendar实例的时间。同时,文章还介绍了如何获取特定地区的日历类型和本地化信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方文档:jse8 https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getFirstDayOfWeek--

所有方法:

 
Modifier and TypeMethod and Description
abstract voidadd(int field, int amount)

Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.

booleanafter(Object when)

Returns whether this Calendar represents a time after the time represented by the specified Object.

booleanbefore(Object when)

Returns whether this Calendar represents a time before the time represented by the specified Object.

voidclear()

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

voidclear(int field)

Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Objectclone()

Creates and returns a copy of this object.

intcompareTo(Calendar anotherCalendar)

Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.

protected voidcomplete()

Fills in any unset fields in the calendar fields.

protected abstract voidcomputeFields()

Converts the current millisecond time value time to calendar field values in fields[].

protected abstract voidcomputeTime()

Converts the current calendar field values in fields[] to the millisecond time value time.

booleanequals(Object obj)

Compares this Calendar to the specified Object.

intget(int field)

Returns the value of the given calendar field.

intgetActualMaximum(int field)

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

intgetActualMinimum(int field)

Returns the minimum value that the specified calendar field could have, given the time value of this Calendar.

static Set<String>getAvailableCalendarTypes()

Returns an unmodifiable Set containing all calendar types supported by Calendar in the runtime environment.

static Locale[]getAvailableLocales()

Returns an array of all locales for which the getInstance methods of this class can return localized instances.

StringgetCalendarType()

Returns the calendar type of this Calendar.

StringgetDisplayName(int field, int style, Locale locale)

Returns the string representation of the calendar field value in the given style and locale.

Map<String,Integer>getDisplayNames(int field, int style, Locale locale)

Returns a Map containing all names of the calendar field in the given style and locale and their corresponding field values.

intgetFirstDayOfWeek()

Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

abstract intgetGreatestMinimum(int field)

Returns the highest minimum value for the given calendar field of this Calendar instance.

static CalendargetInstance()

Gets a calendar using the default time zone and locale.

static CalendargetInstance(Locale aLocale)

Gets a calendar using the default time zone and specified locale.

static CalendargetInstance(TimeZone zone)

Gets a calendar using the specified time zone and default locale.

static CalendargetInstance(TimeZone zone, Locale aLocale)

Gets a calendar with the specified time zone and locale.

abstract intgetLeastMaximum(int field)

Returns the lowest maximum value for the given calendar field of this Calendar instance.

abstract intgetMaximum(int field)

Returns the maximum value for the given calendar field of this Calendar instance.

intgetMinimalDaysInFirstWeek()

Gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, this method returns 1.

abstract intgetMinimum(int field)

Returns the minimum value for the given calendar field of this Calendar instance.

DategetTime()

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

longgetTimeInMillis()

Returns this Calendar's time value in milliseconds.

TimeZonegetTimeZone()

Gets the time zone.

intgetWeeksInWeekYear()

Returns the number of weeks in the week year represented by this Calendar.

intgetWeekYear()

Returns the week year represented by this Calendar.

inthashCode()

Returns a hash code for this calendar.

protected intinternalGet(int field)

Returns the value of the given calendar field.

booleanisLenient()

Tells whether date/time interpretation is to be lenient.

booleanisSet(int field)

Determines if the given calendar field has a value set, including cases that the value has been set by internal fields calculations triggered by a get method call.

booleanisWeekDateSupported()

Returns whether this Calendar supports week dates.

abstract voidroll(int field, boolean up)

Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.

voidroll(int field, int amount)

Adds the specified (signed) amount to the specified calendar field without changing larger fields.

voidset(int field, int value)

Sets the given calendar field to the given value.

voidset(int year, int month, int date)

Sets the values for the calendar fields YEARMONTH, and DAY_OF_MONTH.

voidset(int year, int month, int date, int hourOfDay, int minute)

Sets the values for the calendar fields YEARMONTHDAY_OF_MONTHHOUR_OF_DAY, and MINUTE.

voidset(int year, int month, int date, int hourOfDay, int minute, int second)

Sets the values for the fields YEARMONTHDAY_OF_MONTHHOUR_OF_DAYMINUTE, and SECOND.

voidsetFirstDayOfWeek(int value)

Sets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

voidsetLenient(boolean lenient)

Specifies whether or not date/time interpretation is to be lenient.

voidsetMinimalDaysInFirstWeek(int value)

Sets what the minimal days required in the first week of the year are; For example, if the first week is defined as one that contains the first day of the first month of a year, call this method with value 1.

voidsetTime(Date date)

Sets this Calendar's time with the given Date.

voidsetTimeInMillis(long millis)

Sets this Calendar's current time from the given long value.

voidsetTimeZone(TimeZone value)

Sets the time zone with the given time zone value.

voidsetWeekDate(int weekYear, int weekOfYear, int dayOfWeek)

Sets the date of this Calendar with the the given date specifiers - week year, week of year, and day of week.

InstanttoInstant()

Converts this object to an Instant.

StringtoString()

Return a string representation of this calendar.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值