NSDate early by 1 hour?

断了今生、忘了曾经 提交于 2019-12-13 08:25:53

问题


I am using the following code to set a date object:

NSDate *date = [NSDate date];
        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
        NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
        [components setHour: 18];
        [components setMinute: 00];
        [components setSecond: 00];

        reminderDate = [gregorian dateFromComponents: components];

However, when I NSLog reminderDate I get the following output:

Time: 2012-08-29 17:00:00 +0000

Which is early by one hour, can anyone explain what it is I need to do in order to store the correct date in reminderDate?

Thanks,

Tysin


回答1:


What is your time zone? If you notice, the date that you print has +0 time zone, so if your time zone is +1 is all correct.



来源:https://stackoverflow.com/questions/12177311/nsdate-early-by-1-hour

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