【发布时间】:2014-10-30 15:50:41
【问题描述】:
- (void) dateConverter{
NSString *string = [NSString stringWithFormat:@"%@ %@", [[self dates]objectAtIndex:0], [times objectAtIndex:0]]; // string = 01-10-2014 11:36 AM;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy hh:mm a"];
[dateFormatter setLocale:[NSLocale currentLocale]];
NSDate *date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:string];
NSLog(@"dateFromString = %@", date); // 2014-10-01 18:36:00 +0000
NSTimeInterval timeInterval = [date timeIntervalSince1970];
NSLog(@"dateFromString = %f", timeInterval); // 1412188560.000000
}
我正在将 string 转换为实际的日期对象,但我得到了不同的行为
字符串 = 01-10-2014 上午 11:36
是我试图转换但得到这个的实际值
2014-10-01 18:36:00 +0000
这有什么问题?
【问题讨论】:
-
在我看来完全正常。
-
您在之前的帖子中看到我的回答了吗? stackoverflow.com/questions/26646455/…
-
Swizzling 是最后的解决方案,在这种情况下,所需要的只是使用日期格式化程序。
标签: ios objective-c nsdate nsdateformatter