0
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)

Here is my code to create a local notification. But I am not sure why the newDate will be slower than my current time. for example, Asia/Kuala_Lumpur (current) 2017-09-27 16:00:00 +0000 from the 2 print statements above. my current time is 2017-09-28 17:02:20.974. why slower than 1 day to my current time? if I set the hour to 9, it will be 1am in the morning and it is still slower than my current time. Also, I want to set every morning 9am.

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
Andrew
  • 75
  • 1
  • 6
  • Have you actually tested whether the notification is delivered at the right time? There's most probably nothing wrong with your code, you're just misinterpreting the print statement. Have a look at [this](https://stackoverflow.com/a/46403126/4667835) answer for a similar issue about using `print(Date)`. – Dávid Pásztor Sep 28 '17 at 09:56
  • To make it daily instead of weekly you just need remove the weekday component when setting your time – Leo Dabus Sep 28 '17 at 12:19

0 Answers0