zoukankan      html  css  js  c++  java
  • 日期 时间 星期几

    日期  时间   星期几

    //日期
        NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc]init];
        [dateFormatter2 setDateFormat:@"yyyy年MM月dd日"];
        NSString *date = [dateFormatter2 stringFromDate:[NSDate date]];
    
       NSString *week = [self getChineseCalendarWithDate:[NSDate date]];
    
        self.timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
        [self.timer event:^{
            [self updateTime];
        } timeInterval:NSEC_PER_SEC  delay:0];
        
        [self.timer start];
    }
    -(void)updateTime{
        //时间
        NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
        [dateFormatter1 setDateFormat:@"HH:mm:ss"];
        NSString *time = [dateFormatter1 stringFromDate:[NSDate date]];
        
    }

    //星期几 - (NSString*)getChineseCalendarWithDate:(NSDate *)date{

        NSArray *weekDays=[NSArray arrayWithObjects:

                           @" ",@"星期日",@"星期一",@"星期二", @"星期三", @"星期四", @"星期五", @"星期六", @" ",nil];

        NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];

        NSInteger weekDayFlag = [localeCalendar ordinalityOfUnit:NSCalendarUnitWeekday inUnit:NSCalendarUnitWeekOfMonth forDate:date];

        NSString *weekDay = [NSString stringWithFormat:@"%@",weekDays[weekDayFlag] ];

        return weekDay;

    }

    GCDTimer 一个附件GCD

  • 相关阅读:
    Day4-装饰器
    Day3-递归函数、高阶函数、匿名函数
    Day3-函数及作用域
    Day2-字符编码转换
    Day2-文件操作
    Day2-列表、字符串、字典、集合
    Day1-模块初识
    JavaScript 笔试题
    从JavaScript 数组去重谈性能优化
    prototype
  • 原文地址:https://www.cnblogs.com/OIMM/p/9480292.html
Copyright © 2011-2022 走看看