标签:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
// 1
NSDate *date = [NSDate date];
NSLog(@"时间 %@",[formatter stringFromDate:date]);
NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[[formatter dateFromString:[formatter stringFromDate:date]] timeIntervalSince1970]];
NSLog(@"---timeSP---- %@ ",timeSp);
// 2
NSTimeInterval time=[timeSp doubleValue];
NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
NSLog(@"date:%@",[detaildate description]);
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timeSp doubleValue]];
NSLog(@"1296035591 = %@",confromTimesp);
NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
NSLog(@"confromTimespStr = %@",confromTimespStr);
标签:
原文地址:http://www.cnblogs.com/lyl-/p/4525590.html