Nstimer implementation to a specified time (year, month, day) countdown

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.