开发者

Wrong time when adding event to iCal programmatically

开发者 https://www.devze.com 2023-04-05 02:49 出处:网络
I was trying to add an ical event using this code. EKEventStore *eventStore = [[EKEventStore alloc] init];

I was trying to add an ical event using this code.

EKEventStore *eventStore = [[EKEventStore alloc] init];

EKEvent *event  = [EKEvent eventWithEventSto开发者_JAVA百科re:eventStore];
event.title     = title;

event.startDate = date;
event.endDate   = [[NSDate alloc] initWithTimeInterval:5000 sinceDate:event.startDate];

[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];

Where date is something 2011-09-30 20:30:00 +0000

The event go added on date 1st October with time 2 AM, it is very strange.

I need help.

Thanks.


You are not taking in account the timeZone.

2011-09-30 20:30:00 +0000 the +0000 means GTM, if you set a to plus 4 hours you will get 2011-10-01 02:30:00 +0400 which is the date you are getting.

0

精彩评论

暂无评论...
验证码 换一张
取 消