我有两个NSDate的对象IOS的NSDate没有正确格式化
一个以这种格式
yyyy:MM:dd HH:mm:ss
另一种是在
yyyy-MM-dd HH:mm:ss
有什么区别他们?
我也尝试将第二种格式转换为第一种格式,但由于某种原因,我可以将其转换为正确的NSString,但不在NSDate中,NSDate总是显示为yyyy-MM-dd,我无法找到理由。
这里是代码我没有转换为 - 至:
//photo date has this date 2013-07-21 18:02:13
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:photoDate];
dateString = [dateString stringByReplacingOccurrencesOfString:@"-" withString:@":"];
NSDateFormatter *converter = [[NSDateFormatter alloc] init];
[converter setDateFormat:@"yyyy:MM:dd HH:mm:ss"];
NSDate * newPhotoDate = [converter dateFromString:dateString];
// newPhotoDate still has it in 2013-07-21 18:02:13 but dateString actually is in 2013:07:21 18:02:13
请提供一些代码。 – Paul
NSDate是一个数字。它没有格式。 – Sulthan
如果我做nslog我看到2013-07-21 18:02:13和2013:07:21 18:02:13 –