時間戳轉字符串,單獨寫了一個類方法。轉換方便。



類方法:

//時間戳轉字符串
+(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;
}

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