您好,我试图在Objective C中找到一个解决方案,以获得包含毫秒的音频文件的长度。 目前我只有这段代码:
-(NSString *) DoubleToNSStringTime:(double)valore
{
NSNumber *theDouble = [NSNumber numberWithDouble:valore];
int inputSeconds = [theDouble intValue];
int hours = inputSeconds / 3600;
int minutes = (inputSeconds - hours * 3600 ) / 60;
int seconds = inputSeconds - hours * 3600 - minutes * 60;
NSString *theTime = [NSString stringWithFormat:@"%.2d:%.2d", minutes, seconds];
NSLog(@"TDoubleToNSStringTime= %@", theTime);
return theTime;
}
问题是这样的: 我想获得更精确的timePosition,Minutes:Seconds:Milleseconds
你们中有些人有解决方案吗?
由于
答案 0 :(得分:1)
您无需转换为NSNumber
并返回:
- (NSString *)DoubleToNSStringTime:(double)valore
{
NSInteger interval = (NSInteger)valore;
double milliseconds = (valore - interval) * 1000;
NSInteger seconds = interval % 60;
NSInteger minutes = (interval / 60) % 60;
minutes += (interval / 60);
return [NSString stringWithFormat:@"%02ld:%02ld:%3.0f", minutes, seconds, milliseconds];
}
对于60:45:789
的输入,应该打印3645.789
之类的内容。