//将时间转换成秒 time为 YYYY-MM-dd HH:mm:ss 格式
-(NSString *) getSecondsWithTime:(NSString *)time
{
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *date = [formatter dateFromString:time];
NSString *timeStr = [NSString stringWithFormat:@"%ld",(long)[date timeIntervalSince1970]];
return timeStr;
}
//将秒转换成时间
-(NSString *) getTimeWithSeconds:(NSString *)seconds
{
NSInteger time=[seconds longLongValue];
NSDate *d = [[NSDate alloc]initWithTimeIntervalSince1970:time];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setLocale:[NSLocale systemLocale]];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString*timeString=[formatter stringFromDate:d];
return timeString;
}
//转换成 时分秒
-(NSString *)timeFormatted:(NSInteger)totalSeconds
{
NSInteger seconds = totalSeconds % 60;
NSInteger minutes = (totalSeconds / 60) % 60;
NSInteger hours = totalSeconds / 3600;
return [NSString stringWithFormat:@"%02ld:%02ld:%02ld",hours, minutes, seconds];
}