[英]NSString time format to int64_t
I have an NSString that represents a time in mm:ss
format. 我有一个NSString以mm:ss
格式表示时间。 How do i convert it in int64_t
so i can submit it as a score in game center? 如何在int64_t
转换它,以便我可以在游戏中心中将其作为分数提交?
If you wanted to be rigorous you could use an NSDateFormatter to convert to an NSDate then get an NSTimeInterval from that; 如果要严格,可以使用NSDateFormatter转换为NSDate,然后从中获取NSTimeInterval。 if you wanted to be more direct then you might try something as simple as: 如果您想更直接一些,则可以尝试一些简单的操作:
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.