NSDate 提前 1 小时? [英] NSDate early by 1 hour?

查看:59
本文介绍了NSDate 提前 1 小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码来设置日期对象:

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];

但是,当我 NSLog 提醒日期时,我得到以下输出:

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

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

哪个是早一小时,谁能解释我需要做什么才能在 reminderDate 中存储正确的日期?

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?

谢谢,

酪蛋白

推荐答案

您的时区是什么?如果您注意到,您打印的日期有 +0 时区,所以如果您的时区是 +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.

这篇关于NSDate 提前 1 小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆