NSDate returns wrong date on the first of month

后端 未结 2 778
迷失自我
迷失自我 2021-01-06 01:35

My app used [NSDate date ] function to get current date. Its work fine other days except 1st of every month during AM. i.e Follow Following steps :

2条回答
  •  暖寄归人
    2021-01-06 01:43

    Finally got the solution:

    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...)

    The short version: Use NSDateFormatter to output dates. Don't use -description.

提交回复
热议问题