zoukankan      html  css  js  c++  java
  • 自定义时钟 时间

    1、

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        //定时器 反复执行
        NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    }

    2、

    -(void)updateTime{
        UILabel *timeLable = [[UILabel alloc]initWithFrame:CGRectMake(0,0,200,30)];
        timeLable.backgroundColor = [UIColor clearColor];
        [self.view addSubview:timeLable];
        
        NSDate *currentDate = [NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        NSString *dateString = [dateFormatter stringFromDate:currentDate];
        NSLog(@"现在时间:%@",dateString);
        
        timeLable.text = dateString;
    }
  • 相关阅读:
    Flask--目录
    Linux相关目录
    Mac 提示错误”xcrun: error“
    subprocess模块
    压缩模块
    GitPython模块
    Ansible-ansible命令
    YAML语法
    Ansible-安装
    Ansible-概念
  • 原文地址:https://www.cnblogs.com/dujiahong/p/7864948.html
Copyright © 2011-2022 走看看