IOS 1970到指定时间的秒 转化为指定的日期
View Code
+ (NSString *) secondSince1970ToStr:(long long int)seconds { NSDate *date = [NSDate dateWithTimeIntervalSince1970:seconds]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *str = [formatter stringFromDate:date]; [formatter release]; NSLog(@"str %@",str); return str; } [test secondSince1970ToStr:1360144800]; 输出 2013-02-06 18:00:00
View Code
+ (NSString *) secondToStr:(long long int)milliseconds { long long int tarSeconds = milliseconds; NSDate *tarDate = [NSDate dateWithTimeIntervalSince1970:tarSeconds]; return [self stringFromDate:tarDate withFormat:@"yyyy-MM-dd HH:mm:ss"]; }