iOS 获取当前时间戳和时间

NSDate*senddate = [NSDatedate];

NSLog(@"date1时间戳= %ld",time(NULL));

NSString*date2 = [NSStringstringWithFormat:@"%ld", (long)[senddatetimeIntervalSince1970]];

NSLog(@"date2时间戳= %@",date2);

NSDateFormatter*dateformatter = [[NSDateFormatteralloc]init];

[dateformattersetDateFormat:@"YYYY-MM-dd HH:mm:ss"];

NSString*date1 = [dateformatterstringFromDate:senddate];

NSLog(@"获取当前时间= %@",date1);

//时间戳转时间

NSDate*confromTimesp = [NSDatedateWithTimeIntervalSince1970:[senddatetimeIntervalSince1970]];

NSString*confromTimespStr = [dateformatterstringFromDate:confromTimesp];

NSLog(@"时间戳转时间= %@",confromTimespStr);

// 两个时间戳的间隔返回的是秒

NSTimeIntervaltime = [nowtimeIntervalSinceDate:oldDate];

NSLog(@"time:%f",time/60/60/24);

原文:http://blog.csdn.net/u014286994/article/details/50687440

你可能感兴趣的:(iOS 获取当前时间戳和时间)