![](/img/trans.png)
[英]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.