繁体   English   中英

NSString时间格式为int64_t

[英]NSString time format to int64_t

我有一个NSString以mm:ss格式表示时间。 如何在int64_t转换它,以便我可以在游戏中心中将其作为分数提交?

如果要严格,可以使用NSDateFormatter转换为NSDate,然后从中获取NSTimeInterval。 如果您想更直接一些,则可以尝试一些简单的操作:

NSArray *components = [string componentsSeparatedByString:@":"];
if([components count] != 2)
{
    // some error condition
    return;
}

int64_t totalSeconds = ([[components objectAtIndex:0] integerValue] * 60) +
                             [[components objectAtIndex:1] integerValue];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM