iOS开发-时间戳s的转换

// 转换成当前时间 yyyy-MM-dd HH:mm:ss

- (NSString *)timeFormatted:(int)totalSeconds

{

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:totalSeconds];

    NSTimeZone *zone = [NSTimeZone systemTimeZone];

    NSInteger interval = [zone secondsFromGMTForDate: date];

    NSDate *localeDate = [date  dateByAddingTimeInterval: interval];

    

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

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

    NSString *currentDateString = [dateFormatter stringFromDate:localeDate];

    

    return currentDateString;

}

你可能感兴趣的:(iOS开发)