我有一個字符串文本如下圖所示如何分割獲得一個單位
NSString *total_duration= 2 days 5 hours 6 min
基本上我想在每一個單元以獲得像分鐘。我怎樣才能得到這個
NSInteger *total_duration_inMin=2*24*60+5*60+6
我有一個字符串文本如下圖所示如何分割獲得一個單位
NSString *total_duration= 2 days 5 hours 6 min
基本上我想在每一個單元以獲得像分鐘。我怎樣才能得到這個
NSInteger *total_duration_inMin=2*24*60+5*60+6
好吧,如果你的字符串格式保持同所有的時間,那麼你可以使用這個
NSArray *array = [total_duration componentsSeparatedByString:@" "];
NSInteger a = [[array objectAtIndex:0] intValue] * 24 * 60 + [[array objectAtIndex:2] intValue] * 60 + [[array objectAtIndex:4] intValue];
有幾天是可能的最大值是多少? – Madhu
@Madhumal Gunetileke nops,但只有小時和分鐘..取決於距離... –