let date: NSDate = NSDate()
let cal: NSCalendar = NSCalendar(calendarIdentifier:NSCalendar.Identifier.gregorian)!
cal.timeZone = NSTimeZone.system
print(cal.timeZone)
let newDate: NSDate = cal.date(bySettingHour: 0, minute: 0, second: 0, of: date as Date, options: NSCalendar.Options())! as NSDate
let localNotification = UILocalNotification()
localNotification.fireDate = newDate as Date
localNotification.repeatInterval = NSCalendar.Unit.day
print(newDate)
localNotification.category = "First_Category"
localNotification.alertBody = "Hello from device"
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.applicationIconBadgeNumber = UIApplication.shared.applicationIconBadgeNumber + 1
UIApplication.shared.scheduleLocalNotification(localNotification)
这是我创建本地通知的代码。但我不确定为什么newDate会比我现在的时间慢。例如,Asia / Kuala_Lumpur(当前)2017-09-27 16:00:00 +0000来自上面的2个打印陈述。我现在的时间是2017-09-28 17:02:20.974。为什么我的当前时间慢于1天?如果我将小时设置为9,那将是凌晨1点,它仍然比我当前的时间慢。另外,我想每天早上9点开始设置。