Hi all,
Just wondered if anyone could help me, ive only just started creating apps. I'm working on a count down to christmas app but the end date is an hour faster than it should be ie 82 days 3 hours and it should be 82 days 4 hours for exAmple.
This is my code, could anyone help
Just wondered if anyone could help me, ive only just started creating apps. I'm working on a count down to christmas app but the end date is an hour faster than it should be ie 82 days 3 hours and it should be 82 days 4 hours for exAmple.
This is my code, could anyone help
. -(void)updateLabel{
self.datestart = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags fromDate:datestart toDate:xmasDate options:0];
countdown.text = [NSString stringWithFormat"Days:%02d Hours:%02d Mins:%02d Seconds:%02d", components.day, components.hour, components.minute, components.second ];
countdown.textColor = [UIColor whiteColor];
}
- (void)viewDidLoad {
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *yearComp = [gregorian componentsNSYearCalendarUnit) fromDate:today];
NSInteger year = [yearComp year];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:year];
[comps setMonth:12];
[comps setDay:25];
[comps setHour:00];
[comps setMinute:00];
[comps setSecond:00];
self.xmasDate = [gregorian dateFromComponents:comps];
[comps release];
self.timer = [NSTimer scheduledTimerWithTimeInterval1.0) target:self selectorselector(updateLabel) userInfo:nil repeats:YES];
[super viewDidLoad];
[super viewDidLoad];