Wrong date comes back from NSDateComponents

前端 未结 3 1684
孤独总比滥情好
孤独总比滥情好 2020-12-22 10:51

Why is this giving me the wrong date ?

 NSCalendar *myCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
    NSDateComponents*          


        
3条回答
  •  借酒劲吻你
    2020-12-22 11:43

    Probably the date is correct, but you misunderstood the log:

    Logging a date is always done in TZ +0000. For example, if you are in central europe, you will have the (expected?) date 2013-06-28 05:00:00 +0200, but the log will display the normilzed date 2013-06-28 03:00:00 +0000. This is the same date and time! It is simply expressed in a different way.

    +++

    If your components are in TZ +0000, too, you should set the time zone of the calendar.

提交回复
热议问题