且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NSDate在月初返回错误的日期

更新时间:2022-11-30 23:25:19

最后得到解决方案:

strong> NSDate对象没有与他们相关的时区,并且有一些发布回苹果的人决定NSDate的描述方法,这是NSLog使用的,应该使用GMT + 0而不是本地时间输出区。 (我假设有人有一个错误,他们损坏了他们的区域设置,并导致NSDate的描述方法崩溃,所以错误报告已经提交...)

The point is, NSDate objects don't have a time zone associated with them, and a few releases back someone in Apple decided that NSDate's -description method, which is what NSLog uses, should use GMT+0 and NOT the local time zone for output. (I assume someone had a bug where they corrupted their locale setting, and that caused NSDate's -description method to crash, and so bug reports got filed...)

简短版本:使用NSDateFormatter输出日期。不要使用-description