簡體   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