可可触摸NSDateFormatter和纪元日期 [英] cocoa touch NSDateFormatter and epoch date
本文介绍了可可触摸NSDateFormatter和纪元日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1372620996
它的一部分代码:
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init ];
NSDate * offerDate = [dateFormatter dateFromString:@1372620996];
这返回一个空日期,我很确定我的问题是因为我没有设置在我的NSDateFormatter上的dateStyle。但是,我不知道dateStyle在某个时代的日期是如何使用的。
解决方案
NSDate;
NSString * dateStr = @1372620996;
NSDate * date = [NSDate dateWithTimeIntervalSince1970:[dateStr doubleValue]];
NSLog(@%@,date);
> 2013-06-30 19:36:36 +0000
I have a string that is (I think) an epoch date. Here is the example string:
1372620996
Heres part of the code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *offerDate = [dateFormatter dateFromString:@"1372620996"];
This returns a null date, and I'm pretty sure my problem is because I haven't set a dateStyle on my NSDateFormatter. However, I'm not sure what dateStyle to use for an epoch date.
解决方案
It's actually simpler than that to convert to an NSDate;
NSString *dateStr = @"1372620996";
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[dateStr doubleValue]];
NSLog(@"%@", date);
> 2013-06-30 19:36:36 +0000
这篇关于可可触摸NSDateFormatter和纪元日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文