从NSDate获取错误的字符串值

时间:2014-08-08 09:59:27

标签: ios objective-c

我正在使用AVPlayer。而且我希望获得播放器的当前时间以便为用户显示。 问题是你可以在图像中看到来自NSDate的字符串错误值

enter image description here

这是日期值

enter image description here

此字符串值从日期开始

请帮忙解决。这是我的代码

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;

1 个答案:

答案 0 :(得分:2)

您甚至不需要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];