Structure
A date or time specified in terms of units (such as year, month, day, hour, and minute) to be evaluated in a calendar system and time zone.
--按单元(如年、月、日、小时和分钟)指定的要在日历系统和时区中计算的日期或时间。
struct DateComponents
DateComponents
encapsulates the components of a date in an extendable, structured manner.
--DateComponents以可扩展的结构化方式封装日期的组件。
It is used to specify a date by providing the temporal components that make up a date and time in a particular calendar: hour, minutes, seconds, day, month, year, and so on. It can also be used to specify a duration of time, for example, 5 hours and 16 minutes. A DateComponents
is not required to define all the component fields.
--它通过提供组成特定日历中的日期和时间的时态组件来指定日期:小时、分钟、秒、日、月、年等等。它还可以用于指定持续时间,例如,5小时16分钟。定义DateComponents时,不需要定义它的所有组件字段。
When a new instance of DateComponents
is created, the date components are set to nil
.
--当创建DateComponents的新实例时,日期组件被设置为nil。
init(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year: Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?, weekday: Int?, weekdayOrdinal: Int?, quarter: Int?, weekOfMonth: Int?, weekOfYear: Int?, yearForWeekOfYear: Int?)
Initializes a date components value, optionally specifying values for its fields.
--初始化日期组件值,可选地为其字段指定值。
var calendar: Calendar?
The calendar used to interpret the other values in this structure.
--该日历用于解释此结构中的其他值。
var timeZone: TimeZone?
A time zone.
var isValidDate: Bool
Indicates whether the current combination of properties represents a date which exists in the current calendar.
func isValidDate(in: Calendar) -> Bool
Indicates whether the current combination of properties represents a date which exists in the specified calendar.
var date: Date?
The date calculated from the current components using the stored calendar.
var era: Int?
An era or count of eras.
var year: Int?
A year or count of years.
var yearForWeekOfYear: Int?
The year corresponding to a week-counting week.
var quarter: Int?
A quarter or count of quarters.
var month: Int?
A month or count of months.
var isLeapMonth: Bool?
Set to true if these components represent a leap month.
var weekOfMonth: Int?
A week of the month or a count of weeks of the month.
var weekOfYear: Int?
A week of the year or count of the weeks of the year.
var weekday: Int?
A weekday or count of weekdays.
var weekdayOrdinal: Int?
A weekday ordinal or count of weekday ordinals.
var day: Int?
A day or count of days.
var hour: Int?
An hour or count of hours.
var minute: Int?
A minute or count of minutes.
var second: Int?
A second or count of seconds.
var nanosecond: Int?
A nanosecond or count of nanoseconds.
func value(for: Calendar.Component) -> Int?
Returns the value of one of the properties, using an enumeration value instead of a property name.
func setValue(Int?, for: Calendar.Component)
Set the value of one of the properties, using an enumeration value instead of a property name.
enum Calendar.Component
An enumeration for the various components of a calendar date.
static func != (DateComponents, DateComponents) -> Bool
Returns a Boolean value indicating whether two values are not equal.
static func == (DateComponents, DateComponents) -> Bool
Indicates whether two date component instances are the same.
var description: String
A textual description of the date components.
var debugDescription: String
A textual description of the date components suitable for debugging.
var customMirror: Mirror
A mirror that reflects the date.
var hashValue: Int
The computed hash value of the date.
class NSDateComponents
An object that specifies a date or time in terms of calendar units that bridges to DateComponents
; use NSDateComponents
when you need reference semantics or other Foundation-specific behavior.
typealias DateComponents.ReferenceType
An alias for this value type's equivalent reference type.
init(from: Decoder)
func encode(to: Encoder)
func hash(into: inout Hasher)
CustomDebugStringConvertible
CustomReflectable
CustomStringConvertible
Decodable
Encodable
Equatable
Hashable
ReferenceConvertible
struct Calendar
A definition of the relationships between calendar units (such as eras, years, and weekdays) and absolute points in time, providing features for calculation and comparison of dates.
struct TimeZone
Information about standard time conventions associated with a specific geopolitical region.