Skip to content

Instantly share code, notes, and snippets.

@naoty
Created September 20, 2016 13:34
Show Gist options
  • Save naoty/7eb1910759d9075bc6071ff5be17f68a to your computer and use it in GitHub Desktop.
Save naoty/7eb1910759d9075bc6071ff5be17f68a to your computer and use it in GitHub Desktop.
import Foundation
extension NSDate {
convenience init(year: Int, month: Int, day: Int) {
let now = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: now)
components.year = year
components.month = month
components.day = day
let date = calendar.dateFromComponents(components)
self.init(timeInterval: 0, sinceDate: date!)
}
}
let birthday = NSDate(year: 1987, month: 6, day: 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment