NSString to NSDate conversion problem

人盡茶涼 提交于 2019-11-30 10:15:33

The only output difference I notice is the time is different. If you do not explicitly set the timeZone property of the formatter it will use the system's local timezone. If you expect the times to the be the exact same from you and your client:

[formate setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

That would insure the output is always GMT.

You need to manually set the locale for the NSDateFormatter, so that all your users see the same formatted string. Otherwise, the formatter will use whatever locale is set for the device.

Actually, it's working correctly. The two dates are equivalent, just that one is in the US/Mountain time zone and the other is in the Greenwich time zone. (5:30pm + 7 hours = 12:30 am)

What's the problem here?

In iOS2.x and 3.x the description/datefromstring function returns: 2010-09-24 17:30:00 - 0700

in iOS 4.x it returns this: 2010-09-25 00:30:00 GMT

You could submit a bug to apple.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!