iOS企业级开发实用技术iOS开发文集iOS 开发每天分享优质文章

时间戳转日期字符串

2016-10-21  本文已影响94人  强强刘

时间戳转成一定格式的日期字符串;

应用场景:开发中经常遇到服务端返回数据是时间戳的场景,而在页面展示的时候确实需要显示常见的日期格式;

NSTimeInterval interval=[@"1477016421743" longValue] / 1000.0;

NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];

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

[objDateformat setDateFormat:@"yyyy-MM-dd"];

NSString *timeStr = [NSString stringWithFormat:@"%@",[objDateformat stringFromDate: date]];

上一篇下一篇

猜你喜欢

热点阅读