iphone:NSDateFormatter 返回错误的格式
我添加了这段代码
NSString *dateString=@"March 29, 2012 12:45 PM";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMM dd, yyyy h:mm aaa"];
NSDate *date = [formatter dateFromString:dateString];
,但我收到以下输出:
2012-03-29 07:15:00 +0000
我怎样才能获得实际的格式?
I added this code
NSString *dateString=@"March 29, 2012 12:45 PM";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMM dd, yyyy h:mm aaa"];
NSDate *date = [formatter dateFromString:dateString];
But i am receiving the following output:
2012-03-29 07:15:00 +0000
How can i get the actual format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
时间显示不正确的原因是,当您记录 NSDate 时,它会以您当地的时区向您显示时间。
如果要将日期格式化程序设置为特定时区,可以使用
setTimeZone:
方法。我注意到您的个人资料显示您位于印度,如果我没记错的话,印度使用半小时时区,这将占其报告的 7:15 时间,而不是 12:45。The reason that the time is displaying incorrectly is because when you log the NSDate it will show it to you in your local time zone.
If you want to set your date formatter to a specific time zone you can use the
setTimeZone:
method. I noticed that your profile says you are located in India, and if I recall correctly, India utilizes half hour time zones that would account for the 7:15 time that it is reporting instead of 12:45.