我的代碼是像下面正從NSCalendar一個的NSDate和NSDateComponents
NSDateComponents *components = [[NSDateComponents alloc] init];
components.year = [aDay.year intValue]; // 2012
components.month = [aDay.month intValue]; // 2
components.day = [aDay.day intValue]; // 1
components.hour = components.minute = components.second = 0;
NSDate *now = [self.calender dateFromComponents:components];
約self.calendar,我嘗試了2種方法都:
self.calendar = [NSCalendar currentCalendar];
self.calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
但畢竟這,當我打印日期「現在」,它始終是這樣的:
(gdb) po now
2012-01-31 16:00:00 +0000
日期「現在」應該是2012-02-01 00:00:00
顯然有8小時的差異,我現在在中國,所以我在+800時區我猜?
我該如何解決這個問題?我需要處理時區嗎?
非常感謝!
謝謝!所以問題仍然是關於時區?有沒有什麼方法可以直接獲取用戶當前的時區?就像[NSCalendar currentCalendar]? – 2012-02-01 05:28:49
我檢查了默認的timeZone,它是默認的Asia/Hebin,所以...我能做些什麼? – 2012-02-01 06:18:17