ios - How can I show a NSDate countdown in 000:00:00:00 format? -
ios - How can I show a NSDate countdown in 000:00:00:00 format? -
i have next code show countdown specific date:
nsdate *date=[nsdate date]; int secondsnow=(int)[date timeintervalsince1970]; nsdateformatter *formatter=[[nsdateformatter alloc] init]; [formatter setdateformat:@"yyyy"]; nsstring *launchbegin=[nsstring stringwithformat:@"20120126"]; // come in date of launch here in format yyyymmdd [formatter setdateformat:@"yyyymmdd"]; nsdate *otherdate=[formatter datefromstring:launchbegin]; int secondstarget=(int)[otherdate timeintervalsince1970]; int differenceseconds=secondstarget-secondsnow; int days=(int)((double)differenceseconds/(3600.0*24.00)); int diffday=differenceseconds-(days*3600*24); int hours=(int)((double)diffday/3600.00); int diffmin=diffday-(hours*3600); int minutes=(int)(diffmin/60.0); int seconds=diffmin-(minutes*60); countdownlabel.text=[nsstring stringwithformat:@"%d:%d:%d:%d",days,hours,minutes,seconds]; // want alter 000:00:00:00 nstimer *timer; timer = [nstimer scheduledtimerwithtimeinterval: 0.8 target: self selector: @selector(updatetimetolaunch) userinfo: nil repeats: no]; if(days <= 0 && hours <= 0 && minutes <= 0 && seconds <= 0) { uiimage *image = [uiimage imagenamed: @"end_countdown_highres.png"]; [backing setimage:image]; [facebook sethidden:no]; [twitter sethidden:no]; } how can create output in "000:00:00:00" format rather current "0:0:0:0" format?
[nsstring stringwithformat:@"%03d:%02d:%02d:%02d",days,hours,minutes,seconds];
ios nsdate nsdateformatter nsdatecomponents
Comments
Post a Comment