1.时间戳转字符串
///时间戳转化为字符转0000-00-00 00:00 + (NSString *)time_timestampToString:(NSInteger)timestamp{ NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp]; NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init]; [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"]; NSString* string=[dateFormat stringFromDate:confromTimesp]; return string; }
1.Date转字符串
///date转化为字符转0000-00-00 00:00 + (NSString *)time_dateToString:(NSDate *)date{ NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init]; [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"]; NSString* string=[dateFormat stringFromDate:date]; return string; }
总结
以上所述是小编给大家介绍的iOS开发之时间戳(或date)转字符串的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!