With Nstimer implementation countdown function, nonsense not much said, directly on the code, detailed explanation please refer to comments
[Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (timerfiremethod:) Userinfo:nil Repeats
: YES];
/-(void) Timerfiremethod: (Nstimer *) Thetimer { bool Timestart = YES; nscalendar *cal = [Nscalendar currentcalendar];//defines a Nscalendar object Nsdatecomponents *endtime = [[Nsdatecomponents alloc] init]; //initialization target time ... NSDate *today = [nsdate date]; //Get current time
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];
nsdate *datestring = [Dateformatter datefromstring:todate];
nsstring *overdate = [Dateformatter stringfromdate:datestring];
NSLog (@ "overdate=%@", overdate);
static int year; static int month;
static int day;
static int hour;
static int minute;
static int second; if (Timestart) {//from the NSDate to take out the month, time seconds, but only once
year = [[Overdate substringwithrange:nsmakerange (0, 4)] intvalue];
month = [[Overdate substringwithrange:nsmakerange (5, 2)] intValue];
day = [[Overdate substringwithrange:nsmakerange (8, 2)] intValue];
hour = [[Overdate substringwithrange:nsmakerange (one, 2)] intValue]; minute = [[Overdate substringwithrange:nsmakerange (2)] IntValue
]; second = [[Overdate substringwithrange:nsmakerange (2)] IntValue
]; &nbsP; timestart= NO;
   &NBSP} [endtime setyear:year];
[endtime Setmonth:month];
[endtime Setday:day];
[endtime Sethour:hour];
[endtime Setminute:minute];
[endtime Setsecond:second]; nsdate *overtime = [cal Datefromcomponents:endtime]; The target time is loaded into date //is used to get the specific time difference, which is to unify into the Beijing times unsigned int unitflags = Nsyearcalendarunit| Nsmonthcalendarunit| Nsdaycalendarunit| Nshourcalendarunit| Nsminutecalendarunit|
Nssecondcalendarunit;
nsdatecomponents *d = [cal components:unitflags fromdate:today toDate:overTime options:0];
nsstring *t = [NSString stringwithformat:@ "%d", [D Day]];
nsstring *h = [NSString stringwithformat:@ "%d", [D hour]]; nsstring *fen = [NSString stringwithformat:@ "%d", [D minute]]; if ([D minute] <) { fen = [NSString
stringwithformat:@ "0%d", [D minute]];
&NBSP;&NBSP;&NBSP;&NBSP} nsstring *miao = [NSString stringwithformat:@ "%d", [d second]]; if ([D Second] <) { miao = [NSString
stringwithformat:@ "0%d", [d second]];
&NBSP;&NBSP;&NBSP;&NBSP}// NSLog (@ "===%@ day%@:%@:%@", T,h,fen,miao);
[_longtime settext:[nsstring stringwithformat:@ "%@ Day%@:%@:%@", T,h,fen,miao]; if ([D second] > 0) { //Timing is not yet over, Do_ Something// [_longtime settext:[nsstring stringWithFormat:@ "%@:%@:%@", D
, Fen,miao]]; &NBSP;&NBSP;&NBSP;&NBSP} else if ([d second] = = 0) { //Timing End Do_something &NBSP;&NBSP;&NBSP;&NBSP} else{//timer failure [thetimer invalidate
]; &NBSP;&NBSP;&NBSP;&NBSP} }