【发布时间】:2015-04-02 01:42:57
【问题描述】:
我的应用中有倒计时,当倒计时到达日期时,我需要将文本更改为 FINISH。
代码如下:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd"];
NSDate *startingDate = [NSDate date];
NSDate *endingDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@", currentGame.gameDate]];
NSUInteger unitFlags = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitMinute|NSCalendarUnitSecond;
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *componentsDaysDiff = [gregorianCalendar components:unitFlags
fromDate:startingDate
toDate:endingDate
options:0];
NSString *countdownText = [NSString stringWithFormat:@"%ld Months %ld Days %ld Minutes %ld Seconds", (long)componentsDaysDiff.month, (long)componentsDaysDiff.day, (long)componentsDaysDiff.minute, (long)componentsDaysDiff.second];
gamesCountdownLabel.text = countdownText;
【问题讨论】:
-
只检查是否所有组件都为零...我不明白你的问题。
-
@JoshCaswell 如果您看到我附上的图片,您会发现倒计时 - 4 天。当点击数据库中标签更改为发布的日期时,我需要倒计时
标签: ios objective-c cocoa-touch time uilabel