我想将存储为NSString的Unix时间戳(例如1315401371 )转换为日期格式23:0010.12。
有许多与此相关的类似问题被问到,但我希望使用billymeltdown / nsdate-helper methods
我已经将这两个文件(.h和.m)导入到我的项目中,但还没有更进一步。有一些文档,我已经读过了,但是我仍然是objective C的新手,不知道我是如何实际使用这些库的。
提前谢谢。
发布于 2011-10-11 23:32:56
您应该使用NSDateFormatter
NSTimeInterval timestamp = 1315401371;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm dd MMMM yyyy"]; // use one d for 7 October instead of 07 October
// For english month names
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocale];
[usLocale release];
NSString *dateString = [dateFormatter stringFromDate:date];
[dateFormatter release];https://stackoverflow.com/questions/7728451
复制相似问题