1

您好,我试图在 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;
}

问题是这样的:我想获得更精确的时间位置,分钟:秒:毫秒

你们中的一些人有解决方案吗?

谢谢

4

1 回答 1

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.

于 2013-06-17T18:40:25.170 回答