iOS開發-時間戳s的轉換
阿新 • • 發佈:2019-01-27
// 轉換成當前時間 yyyy-MM-dd HH:mm:ss
- (NSString *)timeFormatted:(int)totalSeconds
{
NSDate *date = [NSDate dateWithTimeIntervalSince1970:totalSeconds];
NSTimeZone *zone = [NSTimeZonesystemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSDate *localeDate = [date dateByAddingTimeInterval
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *currentDateString = [dateFormatter stringFromDate:localeDate];
return currentDateString;
}