Countdown
Write a timer in Viewdidload.
[Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (timerfiremethod:) Userinfo:nil repeats: YES];
Then the method of declaring the timer
-(void) Timerfiremethod: (nstimer*) Thetimer
{
Define a Nscalendar Object
Nscalendar *cal = [Nscalendar Currentcalendar];
Initialize target time
Nsdatecomponents *shibo = [[Nsdatecomponents alloc] init]; [Shibo setyear:2014];
[Shibo Setmonth:12];
[Shibo setday:21];
[Shibo sethour:16];
[Shibo setminute:30];
[Shibo setsecond:0];
Load the target time into date
NSDate *todate = [cal Datefromcomponents:shibo];
Get current time
NSDate *today = [NSDate Date];
To get a specific time difference.
unsigned int unitflags = Nsyearcalendarunit | Nsmonthcalendarunit | Nsdaycalendarunit | Nshourcalendarunit | Nsminutecalendarunit | Nssecondcalendarunit;
Nsdatecomponents *d = [cal components:unitflags fromdate:today todate:todate options:0];
Lab is a global variable
Lab.text = [NSString stringwithformat:@ "%d%d months%d days%d"%d seconds ", [D year],[d Month], [D day],[d Hour], [D minute], [D second]];
}
Get time in this time zone
The time taken by this method is not local time, but GMT time
NSDate *gmtdate = [NSDate Date];
NSLog (@ "currentdate%@", gmtdate);//currentdate 2014-12-04 05:49:57 +0000
local time
Nstimezone *timezone = [Nstimezone systemtimezone];
Nsinteger interval = [TimeZone secondsfromgmt];
NSDate *localedate = [Gmtdate datebyaddingtimeinterval:interval];
NSLog (@ "Localedate%@", localedate);
IOS Countdown and Access time in this time zone