iOS-时间戳转String

-(NSString *)backMsgTime:(NSInteger)time

{

    NSString *timeString = [NSString stringWithFormat:@"%ld",(long)time];

    // 格式化时间

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

    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];

    [formatter setDateStyle:NSDateFormatterMediumStyle];

    [formatter setTimeStyle:NSDateFormatterShortStyle];

    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    

    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]/ 1000.0];

    NSString* dateString = [formatter stringFromDate:date];

    return dateString;

}

你可能感兴趣的:(代码笔记)