标签:
-(void)updateLabel {
NSDate* now = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |NSSecondCalendarUnit;
NSDateComponents *dd = [cal components:unitFlags fromDate:now];
int y = [dd year];
int m = [dd month];
int d = [dd day];
int hour = [dd hour];
int min = [dd minute];
int sec = [dd second];
Lable1.text = [NSString stringWithFormat:@"2d%:2d%:2d%",y,m,d];
Lable2.text =[NSStrinstringWithFormat:@"2d%:2d%:2d%",hour,min,sec];
}
- (void)onTimer {
[viewController updateLabel];
}
在AppDeletate.m文件中增加如下方法:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
标签:
原文地址:http://www.cnblogs.com/niexiaobo/p/4615567.html