marco

Show in context Administrator User since 2016

You are right @Joel_Eisenstat, date manipulation should be easier.
That's the reason why we added the following methods/properties to the new upcoming beta:

Properties

var timeIntervalSinceNow: Float The interval between the date object and the current date and time. (read-only)

var timeIntervalSince1970: Float The interval between the date object and 00:00:00 UTC on 1 January 1970. (read-only)

var era: Int Extract era from current date. (read-only)

var year: Int Extract year from current date. (read-only)

var month: Int Extract month from current date. (read-only)

var day: Int Extract day from current date. (read-only)

var hour: Int Extract hour from current date. (read-only)

var minute: Int Extract minute from current date. (read-only)

var second: Int Extract second from current date. (read-only)

var nanosecond: Int Extract nanosecond from current date. (read-only)

var weekday: Int Extract weekday from current date. The weekday units are the numbers 1 through N (where for the Gregorian calendar N=7 and 1 is Sunday). (read-only)

var weekdayOrdinal: Int The weekday ordinal unit describes ordinal position within the month unit of the corresponding weekday unit. For example, in the Gregorian calendar a weekday ordinal unit of 2 for a weekday unit 3 indicates "the second Tuesday in the month". (read-only)

var quarter: Int Extract quarter from current date. (read-only)

var weekOfMonth: Int Extract the original week of a month calendar unit. (read-only)

var weekOfYear: Int Extract the original week of the year calendar unit. (read-only)

var yearForWeekOfYear: Int Extract the ISO Week Date from current date. (read-only)

Class Methods

func dateWithTimeIntervalSince1970(timeInterval: Float): Date Creates and returns a Date object set to a given number of seconds from 00:00:00 UTC on 1 January 1970.

func dateWithTimeIntervalSinceReferenceDate(timeInterval: Float): Date Creates and returns a Date object set to a given number of seconds from 00:00:00 UTC on 1 January 2001.

func knownTimeZoneNames(): List Returns an array of strings listing the names of all the time zones known to the system.

func tomorrow(): Date Creates and returns a Date object set to tomorrow.

func yesterday(): Date Creates and returns a Date object set to yesterday.

func dateWithDaysFromNow(reference: Int): Date Creates and returns a Date object set by adding reference days to the current date and time.

func dateWithDaysBeforeNow(reference: Int): Date Creates and returns a Date object set by subtracting reference days to the current date and time.

func dateWithHoursFromNow(reference: Int): Date Creates and returns a Date object set by adding reference hours to the current date and time.

func dateWithHoursBeforeNow(reference: Int): Date Creates and returns a Date object set by subtracting reference hours to the current date and time.

func dateWithMinutesFromNow(reference: Int): Date Creates and returns a Date object set by adding reference minutes to the current date and time.

func dateWithMinutesBeforeNow(reference: Int): Date Creates and returns a Date object set by subtracting reference minutes to the current date and time.

Initializers

func Date(timeInterval: Float) Returns a Date object relative to the current date and time by a given number of seconds.

func Date(timeInterval: Float, date: Date) Returns a Date object relative to another given date by a given number of seconds.

func Date(string: String, format: String, timeZone: String) Returns a Date object converted from a textual representations of dates and times.

Methods

func isEqualToDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is exactly equal to a reference date.

func diff(refDate: Date): Float Returns the interval between the receiver and the reference Date parameter. If the receiver is earlier than reference Date, the return value is negative.

func isEqualToDateIgnoringTime(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is equal to a reference Date ignoring the time value.

func isToday(): Bool Returns a Boolean value that indicates whether a given Date is set to today.

func isTomorrow(): Bool Returns a Boolean value that indicates whether a given Date is set to tomorrow.

func isYesterday(): Bool Returns a Boolean value that indicates whether a given Date is set to yesterday.

func isSameWeekAsDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object has the same week as a reference Date.

func isThisWeek(): Bool Returns a Boolean value that indicates whether a given Date is set to current week.

func isNextWeek(): Bool Returns a Boolean value that indicates whether a given Date is set to next week.

func isLastWeek(): Bool Returns a Boolean value that indicates whether a given Date is set to last week.

func isSameMonthAsDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object has the same month than a reference Date.

func isThisMonth(): Bool Returns a Boolean value that indicates whether a given Date is set to current month.

func isNextMonth(): Bool Returns a Boolean value that indicates whether a given Date is set to next month.

func isLastMonth(): Bool Returns a Boolean value that indicates whether a given Date is set to last month.

func isSameYearAsDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object has the same year as a reference Date.

func isThisYear(): Bool Returns a Boolean value that indicates whether a given Date is set to current year.

func isNextYear(): Bool Returns a Boolean value that indicates whether a given Date is set to next year.

func isLastYear(): Bool Returns a Boolean value that indicates whether a given Date is set to last year.

func isEarlierThanDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is earlier than a reference Date.

func isLaterThanDate(refDate: Date): Bool Returns a Boolean value that indicates whether a given Date object is later thana reference Date.

func isInFuture(): Bool Returns a Boolean value that indicates whether a given Date is set to sometime in the future.

func isInPast(): Bool Returns a Boolean value that indicates whether a given Date is set to sometime in the past.

func dateByAddingYears(reference: Int): Date Creates and returns a new Date object set by adding reference years to the current date.

func dateBySubtractingYears(reference: Int): Date Creates and returns a new Date object set by subtracting reference years to the current date.

func dateByAddingMonths(reference: Int): Date Creates and returns a new Date object set by adding reference months to the current date.

func dateBySubtractingMonths(reference: Int): Date Creates and returns a new Date object set by subtracting reference months to the current date.

func dateByAddingDays(reference: Int): Date Creates and returns a new Date object set by adding reference days to the current date.

func dateBySubtractingDays(reference: Int): Date Creates and returns a new Date object set by subtracting reference days to the current date.

func dateByAddingHours(reference: Int): Date Creates and returns a new Date object set by adding reference hours to the current date.

func dateBySubtractingHours(reference: Int): Date Creates and returns a new Date object set by subtracting reference hours to the current date.

func dateByAddingMinutes(reference: Int): Date Creates and returns a new Date object set by adding reference minutes to the current date.

func dateBySubtractingMinutes(reference: Int): Date Creates and returns a new Date object set by subtracting reference minutes to the current date.