时间戳转换成时间

NSString*str= [NSString stringWithFormat:@"%@",list.btime];//时间戳

NSTimeInterval time=[str doubleValue]/1000;

NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];

//实例化一个NSDateFormatter对象

NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];

//设定时间格式,这里可以设置成自己需要的格式

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString*currentDateStr = [dateFormatter stringFromDate:detaildate];


时间转时间戳的方法:

NSString *timeSp =

[NSString stringWithFormat:@"%d", (long)[datenow

timeIntervalSince1970]];

NSLog(@"timeSp:%@",timeSp); //时间戳的值

时间戳转时间的方法

NSDate *confromTimesp =[NSDate dateWithTimeIntervalSince1970:1296035591];

NSLog(@"1296035591= %@",confromTimesp);

NSString*confromTimespStr = [formatter stringFromDate:confromTimesp];

NSLog(@"confromTimespStr=%@",confromTimespStr);

时间戳时间的方法:

NSDateFormatter*formatter=[[NSDateFormatteralloc]init];

[formattersetDateStyle:NSDateFormatterMediumStyle];

[formattersetTimeStyle:NSDateFormatterShortStyle];

[formattersetDateFormat:@"yyyyMMddHHMMss"];

NSDate*date=[formatterdateFromString:@"1283376197"];

NSLog(@"date1:%@",date);

[formatterrelease];

你可能感兴趣的:(时间戳转换成时间)