unexpected result of dateFromComponents:

后端 未结 3 1220
清酒与你
清酒与你 2021-01-21 11:51

the following code

NSCalendar *cal = [NSCalendar currentCalendar];
[cal setFirstWeekday:2];
[cal setMinimumDaysInFirstWeek:4];

NSDateComponents *comp = [[NSDate         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 12:33

    When you call dateFromComponents: you lose all of the timezone and calendar information and are left an NSDate object that contains the moment in time your date components represent, but nothing else. When you use NSLog on your NSDate object, that moment in time is converted to a time in UTC and rendered as a human readable string.

    You need to provide more info about what you're trying to achieve to be able to answer your second question of how to avoid this.

提交回复
热议问题