IOS将后台提供的时间戳格式化成可读的时间格式

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
    NSDate *theday = [NSDate dateWithTimeIntervalSince1970:time];
    NSString *day = [dateFormatter stringFromDate:theday];

我们经常从服务器后台拿到时间戳的时间,以上代码可以实现将时间戳转为可读的时间格式。

你可能感兴趣的:(ios,服务器)