目前我的控制台读取
This is the date: 2013-04-27 00:21:00 +0000
但是在 UIDatePicker (pick) 中,我选择的是 2013-04-26,而不是 27。
-(IBAction)saveList:(id)sender {
NSDateFormatter *pickerFormatter = [[NSDateFormatter alloc] init];
[pickerFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
pickerFormatter.timeZone = [NSTimeZone localTimeZone];
pick.date = [pickerFormatter dateFromString:dateLabel.text];
NSLog(@"This is the date: %@", pick.date);
[ListItemObject saveListItem:[PFUser currentUser] withName:listFieldText withDate:pick.date];
[self.navigationController popViewControllerAnimated:YES];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
这部分工作正常,并在标签中显示正确的日期。
-(IBAction)updateDateLabel:(id)sender {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
dateLabel.text = [formatter stringFromDate:pick.date];
}