给予任何建议或想法以使其得到体现 的由于
从日期选择器获取日期和时间
close
在此处创建并保存EKEvent:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY-MM-dd"
routineDate = dateFormatter.string(from: self.datetimepicker.date)
print(routineDate)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm a"
routineTime = dateFormatter.string(from: self.datetimepicker.date)
print(routineTime)
答案 0 :(得分:3)
尝试将日期保存为日期:
let startDate = self.datetimepicker.date
let endDate = startDate.addingTimeInterval(3600 as TimeInterval)
然后使用它们来创建您的活动:
let event:EKEvent = EKEvent(eventStore: appleEventStore)
event.title = tempDescription
// what should i need to change here for specific date and time?
event.startDate = startDate
event.endDate = endDate
event.isAllDay = false
event.notes = "This is a note"
event.calendar = cal
do {
try appleEventStore.save(event, span: .thisEvent)
print("events added with dates:")
// Adding an Alert 1 hour before the startDate
let reminder = EKAlarm(relativeOffset: -3600)
event.addAlarm(reminder)
print("Saved Event")
} catch let e as NSError {
print(e.description)
return
}
此外,您的事件的创建不应该在DateFormatter声明中。