I have in my app a feature to add an event to calendar, the process involves parsing a string representation of the date (with daylight saving adjustment, and setting the EKEvent startDate to it, here is a snippet:
let eventStore : EKEventStore = EKEventStore()
eventStore.requestAccess(to: .event) { (granted, error) in
if (granted) && (error == nil) {
let event:EKEvent = EKEvent(eventStore: eventStore)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy HH:mm"
// Just for demonstration
let myStartingDate = "16-04-2018 14:00:00"
if let eventDate = dateFormatter.date(from: myStartingDate) {
event.title = "Test event"
event.startDate = eventDate
event.endDate = eventDate.addingTimeInterval(TimeInterval(120 + 20 * 60))
event.notes = "This is a note"
event.location = "some location"
event.calendar = eventStore.defaultCalendarForNewEvents
do {
try eventStore.save(event, span: .thisEvent)
// Success, now open the calendar.
self.openCalendarOn(date: eventDate)
} catch let error as NSError {
print("failed to save event with error : \(error)")
}
}
}
}
Everything was working as expected for some time, but since the UK daylight saving transition, I've noticed that the event on the calendar is one hour ahead
Eg the event I set is "16-04-2018 14:00:00", but the calendar date is "16-04-2018 15 :00:00".
Is there a way to tell EKEvent to disable the daylight saving adjustment? As my string date is already with it.
我发现了问题,显然我在构造时区为gmt + 00:00的DateFormatter对象。删除时区后,ios日历上的时间保持不变。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.