Imitation snapping to the time of remembering
Constructs a date instance with the specified format dateformatter, obtaining the time difference (in seconds) between the build and the current time [NSDate Date]
-(NSString *) countdown
{
NSDateFormatter *dateformatter = [[[[NSDateFormatter alloc] init] autorelease];
[Dateformatter setdateformat:@ "Yyyy-mm-dd hh-mm-ss"];
NSDate *date = [dateformatter dateformstring:@ "2015-12-18 9:15:00"];
Nsinteger poordate = [date timeintervalsincedate:[nsdate Date]];
Nsinteger minute = poordate/60;//count minutes
if (!poordate)
{
Self.lable.text = @ "Activity is in progress, hurry to buy it ... ”;
self.button.enabled = yes;//When the time difference is 0 o'clock, is snapped button for the active state
[Self.timer invalidate];//Stop Countdown
}
if (minute >= 60)
{
Nsinteger hour = minute/60;//Compute hour
if (hour >= 24)
{
Nsinteger day = hour/24;//Compute days
return [NSString stringwithformstring:@]%02ld days%02ld hours%02ld minutes%02ld seconds from start, day,hour% 24,minute% 60,poordate% 60];
}
Else
return [[NSString stringwithformstring:@]%02d days%02ld hours%02ld minutes%02ld seconds from start, 0,hour,minute% 60,poordate% 60];
}
Else
return [NSString stringwithformstring:@]%02d days%02d hours%02ld minutes%02ld seconds from start, 0,0,minute,poordate% 60];
}
-(void) Testrepeattimer
{
if (!timer)//Build a Timer_ instance with a time interval of 1 seconds, Self call countdown Method (Countdown), repeats need to repeat
{
Timer_ = [Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (Countdown) Userinfo:nil repeats: YES];
}
}
Nstimer implementation to a specified time (year, month, day) countdown