20200714--iOS之DateInterval结构体,表征日期间隔

Structure

DateInterval

The span of time between a specific start date and end date.

--表示开始日期与结束日期之间的跨度的结构体

 

Declaration     --声明

iOS, tvOS, watchOS

struct DateInterval

macOS, Mac Catalyst

struct DateInterval, Codable

Overview           --概览

DateInterval represents a closed date interval in the form of [startDate, endDate]. It is possible for the start and end dates to be the same with a duration of 0. DateInterval does not support reverse intervals i.e. intervals where the duration is less than 0 and the end date occurs earlier in time than the start date.

--DateInterval表示一个封闭的日期间隔,其形式为[startDate, endDate]。开始和结束日期可能相同,持续时间为0。DateInterval不支持反向间隔,即持续时间小于0且结束日期比开始日期早的间隔。

 

Topics      --专题

Creating a Date Interval        --创建日期间隔结构体

init()

Initializes an interval with start and end dates set to the current date and the duration set to 0.

--初始化将开始和结束日期设置为当前日期、持续时间设置为0的间隔。

 

init(start: Date, duration: TimeInterval)

Initializes an interval with the specified start date and duration.

--使用指定的开始日期和持续时间初始化间隔。

 

init(start: Date, end: Date)

Initializes an interval with the specified start and end date.

--使用指定的开始和结束日期初始化间隔。

 

Accessing Start Date, End Date, and Duration        --访问开始、结束日期,时间间隔

var start: Date

The start date.

var end: Date

The end date.

var duration: TimeInterval

The duration.

 

Comparing Date Intervals              --比较日期间隔

static func != (DateInterval, DateInterval) -> Bool

Returns a Boolean value indicating whether two values are not equal.

static func < (DateInterval, DateInterval) -> Bool

Indicates whether one date interval is strictly less than another.

static func <= (DateInterval, DateInterval) -> Bool

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

static func == (DateInterval, DateInterval) -> Bool

Indicates whether two date intervals are the same.

static func > (DateInterval, DateInterval) -> Bool

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

static func >= (DateInterval, DateInterval) -> Bool

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

 

Determining Intersections               --确定两个间隔实例的交集

func intersection(with: DateInterval) -> DateInterval?

Returns an interval that represents the interval where the given date interval and the current instance intersect.

--返回一个间隔,该间隔表示给定日期间隔与当前实例相交的间隔。

 

func intersects(DateInterval) -> Bool

Indicates whether this interval intersects the specified interval.

--指示此间隔实例是否与指定的间隔相交。

 

Determining Whether a Date Occurs Within a Date Interval        

--确定某个日期是否在某个日期间隔内发生

func contains(Date) -> Bool

Indicates whether this interval contains the given date.

 

Describing a Date Interval            --描述日期间隔实例

var description: String

A textual description of the date interval.

var debugDescription: String

A textual description of the date interval suitable for debugging.

var customMirror: Mirror

A mirror that reflects the date interval.

--反映日期间隔的镜像。

var hashValue: Int

The computed hash value for the date interval.

 

Using Reference Types         --使用引用类型

class NSDateInterval

An object representing the span of time between two dates that bridges to DateInterval; use NSDateInterval when you need reference semantics or other Foundation-specific behavior.

typealias DateInterval.ReferenceType

An alias for this value type's equivalent reference type.

 

Initializers         --构造器

init(from: Decoder)

 

Instance Methods          --实例方法

func compare(DateInterval) -> ComparisonResult

Compares two intervals.

func encode(to: Encoder)

func hash(into: inout Hasher)

Operator Functions         --操作符函数

static func ... (DateInterval) -> PartialRangeFrom

Returns a partial range extending upward from a lower bound.

static func ... (DateInterval) -> PartialRangeThrough

Returns a partial range up to, and including, its upper bound.

static func ... (DateInterval, DateInterval) -> ClosedRange

Returns a closed range that contains both of its bounds.

static func ..< (DateInterval) -> PartialRangeUpTo

Returns a partial range up to, but not including, its upper bound.

static func ..< (DateInterval, DateInterval) -> Range

Returns a half-open range that contains its lower bound but not its upper bound.

 

Relationships         --继承关系

Conforms To

  • Comparable
  • CustomDebugStringConvertible
  • CustomReflectable
  • CustomStringConvertible
  • Decodable
  • Encodable
  • Hashable
  • ReferenceConvertible

See Also

Date Representations

struct Date

A specific point in time, independent of any calendar or time zone.

typealias TimeInterval

A number of seconds.

你可能感兴趣的:(iOS时间处理)