iOS 获取当前时间并且显示走在视图上
2016-10-28 18:12
501 查看
// 时间戳在走并且显示Demo #import "RootViewController.h" @interface RootViewController () { UILabel *labelTime; NSTimer *timeNow; } @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor orangeColor]; labelTime = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 50)]; labelTime.backgroundColor = [UIColor redColor]; [self.view addSubview:labelTime]; timeNow = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES]; //获取系统时间 NSDate * senddate=[NSDate date]; NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"HH:mm"]; NSString * locationString=[dateformatter stringFromDate:senddate]; NSLog(@"-------%@",locationString); //获取系统时间 NSCalendar * cal=[NSCalendar currentCalendar]; NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit; NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate]; NSInteger year=[conponent year]; NSInteger month=[conponent month]; NSInteger day=[conponent day]; NSString * nsDateString= [NSString stringWithFormat:@"%4d年%2d月%2d日",year,month,day]; NSLog(@"+++++++++++++%@",nsDateString); } - (void)timerFunc { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MM/dd/YY HH:mm:ss"]; NSString *timestamp = [formatter stringFromDate:[NSDate date]]; [labelTime setText:timestamp];//时间在变化的语句 NSLog(@"%@",timestamp); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
相关文章推荐
- iOS 获取当前时间并且显示走在视图上
- [IOS]iphone之在视图上显示当前的时间,并且时间还在走。
- [IOS]iphone之在视图上显示当前的时间,并且时间还在走。
- IOS/iphone之在视图上显示当前的时间,并且时间还在走
- [IOS]iphone之在视图上显示当前的时间,并且时间还在走。
- IOS---如何获取当前的日期和时间(阴历阳历),并显示带阴历阳历24节气的日历
- iOS获取当前正在显示的窗口、视图控制器、视图
- iOS 获取当前时间,并按照要求格式显示
- iOS获取当前时间日期,并按规定格式显示【原创】
- iOS-获取当前时间的年、月、日、时、分、秒
- js获取当前时间并以时钟显示
- iOS获取当前时间
- cocos2d-x在win32和iOS、android下获取当前系统时间的方法
- ios 获取当前时间
- cocos2d-x在win32和iOS、android下获取当前系统时间的方法
- IOS笔记:获取当前时间,并转化为一定格式字符串
- [iOS]获取当前界面上显示的键盘UIKeyboard方法
- Flex 获取当前时间和获取当前时间减去一天的时间并且格式化为年月日时分秒的形式
- IOS MPMoviePlayerViewController 获取当前音频文件播放时间点
- IOS获取当前时间