Created
December 23, 2014 22:01
-
-
Save natecook1000/4219d013d1214246fdcd to your computer and use it in GitHub Desktop.
Actually sane ways of getting a particular NSDate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // (c) 2014 Nate Cook, licensed under the MIT license | |
| extension NSDate { | |
| /// Initializes an NSDate instance with the given date and time parameters. | |
| convenience init(year: Int, month: Int, day: Int, hour: Int, minute: Int = 0, second: Int = 0) { | |
| var components = NSDateComponents() | |
| components.year = year | |
| components.month = month | |
| components.day = day | |
| components.hour = hour | |
| components.minute = minute | |
| components.second = second | |
| self.init(timeInterval: 0, sinceDate: NSCalendar.currentCalendar().dateFromComponents(components)!) | |
| } | |
| /// Initializes an NSDate instance with the given date parameters. | |
| convenience init(year: Int, month: Int, day: Int) { | |
| self.init(year: year, month: month, day: day, hour: 0) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment