我想将日期对象保存到我的应用程序的后端。这是代码:
NSDate *date = self.birthPickerView.date;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString *stringFromDate = [formatter stringFromDate:date];
NSLog(@"%@", stringFromDate);
NSDate *endDate = [formatter dateFromString:stringFromDate];
[formatter release];
NSLog(@"%@", endDate);
// Save to database
[user setObject:endDate forKey:@"birth"];
这是打印出来的结果:
1985-03-05 00:00:00
1985-03-04 23:00:00 +0000
结束日期不对。我想保存1985-03-05
在数据库中。你能帮我出什么问题吗?
编辑
[self.birthPickerView setTimeZone:[NSTimeZone localTimeZone]];
NSLog(@"%@", self.birthPickerView.date);
NSLog(@"%@", self.birthPickerView.timeZone);
[user setObject:self.birthPickerView.date forKey:self.navTitle];
此代码保存1984-03-04 23:00:00
在数据库中。它有什么问题?