Sets an NSTtimer to display the current time,
Define NSTimer usage: Time Interval NSTimeInterval floating point type, event proxy
Delegate and event processing method @ selector ();
+ (NSTimer *) scheduledTimerWithTimeInterval :( NSTimeInterval) ti target :( id) aTarget selector :( SEL) aSelector userInfo :( id) userInfo repeats :( BOOL) yesOrNo; to initialize a time Timer
Nstcoa is a common Timer class in Cocoa. The basic operations are as follows:
The handleTimer method can be customized. You can create a timer as needed, and handleTimer can be executed every 1.0 seconds.
First, obtain the Time of the specified city.
NSString * tmpTimeStr;
NSDate * nowdate = [[NSDate alloc] init];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
NSTimeZone * timeZone = [NSTimeZone timeZoneWithName: @ "Asia/Shanghai"];
[Formatter setTimeZone: timeZone];
[Formatter setDateFormat: @ "YYYY-MM-dd-HH-mm-ss"];
NSString * timeStr = [formatter stringFromDate: nowdate];
In this way, the time format is NSString, and NSTimer is set as follows:
NSTimeInterval timeinteger = 1.0;
// Timer
Nstmer * timer;
Timer = [NSTimer scheduledTimerWithTimeInterval: timeInterval
Target: self
Selector: @ selector (showNowTime :)
UserInfo: nil
Repeats: YES];
Set the current time for each second. In this way, the use of an NSTimer is realized.