I have a time picker in which the user picks the time and I am sending a notification to user ten minutes before or after the time user picked.Suppose if the user picks time as 11:00 AM then I want the notification to trigger at 10:55 AM. I am unable to subtract and add ten minutes to the time. As I am new to this Please help..I have spent a lot of time on it still not able to solve this. Any help is appreciated
Asked
Active
Viewed 196 times
2 Answers
0
You could subtract minutes using the Calendar
:
Calendar.current.date(byAdding: .minute, value: -10, to: yourDate)

Marwen Doukh
- 1,946
- 17
- 26
0
Use Calendar of iOS.
let beforeThreeMinutes = Calendar.current.date(byAdding: .minute, value: -3, to: datePicker.date)

Sundeep Saluja
- 1,089
- 2
- 14
- 36
-
thank you for your answer...just have one query if have time like this 11:59AM how can I subtract 10 minutes from here. – Aadhar Mathur Jul 16 '19 at 10:41
-
Date from DatePicker can be in any format, that should not cause any issue. – Sundeep Saluja Jul 16 '19 at 11:58