UIDatePickerModeDateAndTime
返回格式为
2012-12-20 07:15:18 +0000.
如何从输出中删除 +0000
?
我想截图,但是我的声望不够,我希望它能解决我的问题。
最佳答案
- (IBAction)dateChanged:(UIDatePicker *)sender {
NSDate *date = sender.date;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterShortStyle]; // if you want to show the date to the user
[df setTimeStyle:NSDateFormatterShortStyle]; // if you want to show the date to the user
// [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // if you want to use the date for your model
NSString *dateString = [df stringFromDate:date];
NSLog(@"%@", dateString);
}
如果您想向用户显示日期,请使用 setDateStyle:
和 setTimeStyle:
,因为它们可以识别区域并以正确的格式生成输出。
如果您只需要后端的日期(例如创建文件名),请使用 setDateFormat:
。
关于ios - UIDatePickerModeDateAndTime 格式 2012-12-20 07 :15:18 +0000 without +0000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13967124/