ios - 获取音频持续时间字符串以 float 值
<p><pre><code>{
duration = "00:06:29";
id = 7;
}
NSNumberFormatter *numberFormatter = [ init];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
float value = .floatValue;
NSLog(@"Current audio %f",value);
</code></pre>
<p>out 是 <strong>当前音频 0.0000</strong></p>
<p>如何将持续时间字符串设为浮点值?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>最简单的方法是</p>
<pre><code>NSString *duration = @"00:06:29";
NSArray *array = ;
NSLog(@"Current hrs %ld",(long)[(NSString *)(array) integerValue]);
NSLog(@"Current min %ld",(long)[(NSString *)(array) integerValue]);
NSLog(@"Current sec %ld",(long)[(NSString *)(array) integerValue]);
</code></pre>
<p>否则你也可以使用 <code>NSDate</code> & <code>NSDateFormatter</code>。</p>
<h3>编辑</h3>
<hr/>
<p>使用 <code>NSDate</code>,注意小时部分不应超过 23 否则结果可能与预期不符。</p>
<pre><code>NSString *duration = @"00:06:29";
NSDateFormatter *formatter = ;
formatter.dateFormat = @"HH:mm:ss";
NSDate *date = ;
NSCalendar *calendar = ;
NSDateComponents *components = ;
NSLog(@"hrs %ld", (long)components.hour);
NSLog(@"min %ld", (long)components.minute);
NSLog(@"sec %ld", (long)components.second);
</code></pre></p>
<p style="font-size: 20px;">关于ios - 获取音频持续时间字符串以 float 值,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41329321/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41329321/
</a>
</p>
页:
[1]