Ios 从NSDate获取错误的字符串值
我用的是AVPlayer。我想得到玩家的当前时间,以显示给用户。 问题是字符串从图像中可以看到的NSDate中获取了错误的值 这是日期值 这个字符串值是从日期开始的 请帮忙解决。这是我的密码Ios 从NSDate获取错误的字符串值,ios,objective-c,Ios,Objective C,我用的是AVPlayer。我想得到玩家的当前时间,以显示给用户。 问题是字符串从图像中可以看到的NSDate中获取了错误的值 这是日期值 这个字符串值是从日期开始的 请帮忙解决。这是我的密码 NSDate* d = [NSDate dateWithTimeIntervalSince1970:CMTimeGetSeconds(mPlayer.currentTime)]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]
NSDate* d = [NSDate dateWithTimeIntervalSince1970:CMTimeGetSeconds(mPlayer.currentTime)];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"mm:ss"];
NSString* result = [dateFormatter stringFromDate:d];
avPlayerLabel.text = result;
您甚至不需要
NSDateFormatter
:
Float64 time = CMTimeGetSeconds(mPlayer.currentTime) + 0.5;
unsigned minutes = (unsigned)time / 60;
unsigned seconds = (unsigned)time % 60;
avPlayerLabel.text = [NSString stringWithFormat:@"%02u:%02u", minutes, seconds];
@AltafBangash我不明白你的意思。我的意思是,实际视频的持续时间是7秒,但这里的持续时间是6秒。@AltafBangash你是否通过查看调试器中
time
变量的值来确认这一点?是,事实上,这会上升到6.8秒,但我不知道我们如何才能得到这个值case@AltafBangash我添加了一个简单的修复程序,以获得最接近的秒数。编译器编译代码时,时间会流逝,因此当前时间会更改几秒钟。这就是为什么编译时会得到不同的值。@Neeku?哈?@Droppy你还不清楚什么?@Neeku:根据定义的数据(日期)赋值,那么编译器编译代码时时间怎么会流逝呢?对,我的错!别理它|