I need to check to see if the current date is during daylight savings time. In pseudocode that would be like this:
let date = NSDate()
if date.isDaylightSavingsTime {
print("Success")
}
I haven't been able to find the solution to this anywhere on the internet.
Daylight savings time will affect local scheduled flight times the same way it will affect your live television schedule. It will affect apparent flight duration if the departure and arrival airports switch to DST on different days of the year, but actual time in the air will remain the same.
Clocks Back or Forward? “Spring forward, fall back” is one of the little sayings used to remember which way to set your watch. You set your clock forward one hour in the spring when DST starts (= lose 1 hour), and back one hour when DST ends in the fall (= regain 1 hour).
As is often said twice a year on the occasion of Daylight Saving Time's start and stop, “spring forward, fall back,” as clocks move forward an hour in March and back an hour in November.
There are two time zones that do not observe daylight saving time and that have the same UTC offset (-06:00): (UTC-06:00) Central America. (UTC-06:00) Saskatchewan.
An NSDate
alone represents an absolute point in time.
To decide if a date is during daylight savings time or not
it needs to be interpreted in the context of a time zone.
Therefore you'll find that method in the NSTimeZone
class and not
in the NSDate
class. Example:
let date = NSDate()
let tz = NSTimeZone.localTimeZone()
if tz.isDaylightSavingTimeForDate(date) {
}
Update for Swift 3/4:
let date = Date()
let tz = TimeZone.current
if tz.isDaylightSavingTime(for: date) {
print("Summertime, and the livin' is easy ... 🎶")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With