日期 时间 星期几

日期  时间   星期几

 

//日期
    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

 

posted @ 2018-08-15 11:11  OIMMZC  阅读(144)  评论(0编辑  收藏  举报