时间戳转换成时间

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];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容