2010-07-15 61 views
0

我怎麼樣,在HH:mm:ss格式中給出兩次比較然後確定哪個是以後的時間。iphone - 比較兩次

12:00:00 & 14:00:00

我如何確定14:00:00是以後

回答

1

查找到NSDateFormatterinitWithDateFormat:allowNaturalLanguage:dateWithString),用於將您輸入的字符串進入NSDate實例。然後在產生的NSDate上使用如earlierDate:compare:等方法。

+0

好的謝謝!我會看一看 – Kenneth 2010-07-15 06:10:56

1

要添加到以前的答案,如果你確實有兩個NSString的與@「12:00:00」和@「14:00:00」你可以擺脫:

NSString *timeA, *timeB; // <-- these are your two times in the format 
    // HH:mm:ss where HH is 24h format (no am/pm) and midnight is 00 
    // and you always have two digits (i.e. 12:3:50 for 3m50s past 12 is 
    // always shown as 12:03:50) ... 
BOOL timeAIsSooner = [[[timeA componentsSeparatedByString:@":"] 
     componentsJoinedByString:@""] intValue] 
    < [[[timeB componentsSeparatedByString:@":"] 
     componentsJoinedByString:@""] intValue];