0

How would I set a date to a specific time? I am trying to implement notifications into my app and want to set the time for my notification to 12am as a default if the time has not been set. I have a date and a time variable and if the date is set but not the time then the time should automatically be set to 12am and if both are set then the date and time should be used for triggering the notification.

Mark Brownsword
  • 2,287
  • 2
  • 14
  • 23
  • Setting a time to midnight is discussed in [this post](https://stackoverflow.com/questions/26189656/how-can-i-set-an-nsdate-object-to-midnight), look for answers about startOfDay. – Mark Brownsword May 15 '22 at 03:50
  • If you want midnight on a date, use `Calendar.startOfDay(for:)`. If you want some arbitrary time, use `Calendar.date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:)` – Duncan C May 15 '22 at 23:55

0 Answers0