我在我的nib文件中有一個NSDatePicker。在代碼中,我設置它的時區是GMT日曆的時區:關於這一點我填充程序的日期選擇器NSDatePicker時區怪異
[datePicker setTimeZone:[calendar timeZone]];
我只真正關心的時間(小時,分):
NSDate *anyDate = [NSDate date];
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:anyDate];
[components setHour:hours];
[components setMinute:minutes];
NSDate *newDate = [calendar dateFromComponents:components];
[datePicker setDateValue:newDate];
這正確具有將日期選擇器時間設置爲我想要的時間的預期效果。因此,如果小時數是8,分鐘數是30,則日期選擇器顯示8:30。然而,如果我在日期選擇器的小時字段中輸入8,它將顯示爲3.某些奇怪的事情正在與時區相關,但我不知道在哪裏...
你有日期格式化程序連接到日期選擇器嗎? – jtbandes