24 小时日期的 NSDateFormatter dateFromString 给出了错误的时间
我想将事件添加到本机日历。我在从字符串获取日期准确时间时遇到问题。我已经设置了区域设置,24 小时格式。但仍然遇到同样的错误。
EKEvent *event = [EKEvent eventWithEventStore:self.eventStore];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale =[[[NSLocalealloc]initWithLocaleIdentifier:@"en_US_POSIX"]autorelease];
[dateFormatter setLocale:locale];
[dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"];
event.startDate=[dateFormatter dateFromString:@"10/02/2011 15:39"];
event.startDate 设置为: 2011-02-10 10:09:00 GMT
任何人都可以帮忙吗???
I want to add event to native calender.I am having problem in getting date accurate time from string. I have set locale,24 hr format. but still getting the same bug.
EKEvent *event = [EKEvent eventWithEventStore:self.eventStore];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale =[[[NSLocalealloc]initWithLocaleIdentifier:@"en_US_POSIX"]autorelease];
[dateFormatter setLocale:locale];
[dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"];
event.startDate=[dateFormatter dateFromString:@"10/02/2011 15:39"];
And event.startDate is getting set as : 2011-02-10 10:09:00 GMT
Can anyone help???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的 event.startDate 正在重新初始化,
它显示当前时间,我认为是这样。
检查是否有类似
编辑:
的代码,您如何检查 event.startDate 值?如果是使用 NSLog,请检查此答案。
I think your event.startDate is re initializing,
Its showing the current time, i think so.
Check whether any code there like
EDIT:
how you checking your event.startDate vale? If it is by using NSLog check this answer.