[英]NSTimeInterval, NSDate & int64_t Yields Unreasonable Time Calculation
[英]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.