简体   繁体   English

NSString时间格式为int64_t

[英]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.

相关问题 NSTimeInterval,NSDate和int64_t产生不合理的时间计算 - NSTimeInterval, NSDate & int64_t Yields Unreasonable Time Calculation 从NSDictionary存储和检索int64_t:NSNumber vs NSString - Storing and retrieving an int64_t from an NSDictionary: NSNumber vs NSString 将int64_t转换为NSInteger - Convert int64_t to NSInteger iOS Game Center 提交 float 而不是 int64_t - iOS Game Center submit float instead of int64_t 我怎样才能将 int 等于 int64_t 而不得到转换丢失整数精度警告? - How can i equal a int to a int64_t with out getting the conversion loses integer precision warning? Objective-C:将float转换为int64_t而不会造成精度损失 - Objective-C: Convert float to int64_t without precision loss 为什么C标准提供不定尺寸的类型(int,long long,char与int32_t,int64_t,uint8_t等)? - Why does the C standard provide unsized types (int, long long, char vs. int32_t, int64_t, uint8_t etc.)? 以12小时时间格式转换NSString - Convert NSString in 12 hour time format Format指定类型'int'但参数的类型为'NSString *' - Format specifies type 'int' but the argument has type 'NSString *' 如何将int格式化为NSString,并在iOS中显示正数的+号 - How to format int to NSString with displaying the + sign for positive numbers in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM