I have tried this in playgrounds (I show in comments what it's printed):
extension NSDate {
static func currentDate() -> NSDate {
let calendar = NSCalendar.currentCalendar()
calendar.timeZone = NSTimeZone.localTimeZone()
calendar.locale = NSLocale.currentLocale()
let components = calendar.components([.Year, .Month, .Day], fromDate: NSDate())
components.hour = 00
components.minute = 00
components.second = 00
return calendar.dateFromComponents(components)! // "Dec 29, 2015, 12:00 AM"
}
}
print(NSDate.currentDate()) // "2015-12-28 22:00:00 +0000
Anyone has an idea what is going on here ?
I just want the current date (year/month/day). I made this extension because I had problems with NSDate()
, it was off by 2 hours (showing 11.24 am, instead of 1.24 pm)