时间戳转字符串,单独写了一个类方法。转换方便。



类方法:

//时间戳转字符串
+(NSString *)getTimeString:(long int)time;  



//时间戳转字符串
+(NSString *)getTimeString:(long int)time
{
    NSTimeInterval timeInterval = time + 28800;
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    NSString * dateStr = [dateFormatter stringFromDate:date];
    
    return dateStr;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章