Date Extensions

Omar Albeik edited this page Dec 29, 2016 · 10 revisions

Date extensions


Name Description
DayNameStyle Day name format.
MonthNameStyle Month name format.


Name Description
calendar User’s current calendar.
era Era.
year Year.
quarter Quarter.
month Month.
weekOfYear Week of year.
weekOfMonth Week of month.
weekday Weekday.
day Day.
hour Hour.
minute Minutes.
second Seconds.
nanosecond Nanoseconds.
isInFuture Check if date is in future.
isInPast Check if date is in past.
isInToday Check if date is in today.
isInYesterday Check if date is in yesterday.
isInTomorrow Check if date is in tomorrow.
iso8601String ISO8601 string of format (yyyy-MM-dd'T'HH:mm:ss.SSS) from date.
nearestFiveMinutes Nearest five minutes to date.
nearestTenMinutes Nearest ten minutes to date.
nearestQuarterHour Nearest quarter hour to date.
nearestHalfHour Nearest half hour to date.
nearestHour Nearest hour to date.
timeZone Time zone used by system.
unixTimestamp UNIX timestamp from date.


Name Return Description
add(_ component: Calendar.Component, value: Int) -- Add calendar component to date.
adding(_ component: Calendar.Component, value: Int) Date Date by adding multiples of calendar component.
beginning(of component: Calendar.Component) Date? Data at the beginning of calendar component.
changing(_ component: Calendar.Component, value: Int) Date Date by changing value of calendar component.
dateString(ofStyle style: DateFormatter.Style = .medium) String Date string from date.
dateTimeString(ofStyle style: DateFormatter.Style = .medium) String Date and time string from date.
dayName(ofStyle style: DayNameStyle = .full) String Day name from date.
monthName(ofStyle style: MonthNameStyle = .full) String Month name from date.
end(of component: Calendar.Component) Date? Date at the end of calendar component.
isInCurrent(_ component: Calendar.Component) Bool Check if date is in current given calendar component.
timeString(ofStyle style: DateFormatter.Style = .medium) String Time string from date


Name Description
init?(calendar: Calendar?, timeZone: TimeZone?, era: Int?, year: Int?, month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?, nanosecond: Int?) Create a new date form calendar components.
init(iso8601String: String) Create date object from ISO8601 string.
init?(unixTimestamp: Double) Create new date object from UNIX timestamp.