将时间秒数转换为格式化后的字符串
// 格式化后的字符串
+ (NSString *)getStringFormatBySeconds:(float)seconds{
// 格式化时间 从浮点类型转换成"00:00"字符串
NSString *formatTime = [NSString stringWithFormat:@"%02ld:%02ld",(NSInteger)seconds / 60,(NSInteger)seconds % 60];
return formatTime;
}
将格式化后的字符串转化为时间秒数
+ (float)getSecondsFormatByString:(NSString *)string{
NSArray *tempArr = [string componentsSeparatedByString:@":"];
return [[tempArr firstObject]integerValue] * 60.0 + [[tempArr lastObject]integerValue];
}
本文介绍了如何使用Objective-C进行时间格式的转换,包括将秒数转换为格式化的时间字符串(如00:00),以及如何将这种格式化的字符串重新转换回秒数。这些方法适用于需要显示计时或持续时间的应用场景。

2137

被折叠的 条评论
为什么被折叠?



