zoukankan      html  css  js  c++  java
  • iOS 获取当前时间 年、月、日、周几

        NSDate * nowDate = [NSDate new];

        NSCalendar *calendar = [NSCalendar currentCalendar];

        NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit;

        NSArray * weekTitleArray = @[@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六"];

        NSArray * monthTitleArray = @[@"一月",@"二月",@"三月",@"四月",@"五月",@"六月",@"七月",@"八月",@"九月",@"十月",@"十一月",@"十二月"];

        NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:nowDate];

        headerView.monthLabel.text = monthTitleArray[[dateComponent month] - 1];

        

        headerView.weekLabel.text = weekTitleArray[[dateComponent weekday] - 1];

        NSInteger day = [dateComponent day];

        headerView.dateLabel.text = (day < 10 ? [NSString stringWithFormat:@"0%ld",day] : [NSString stringWithFormat:@"%ld",day]);

  • 相关阅读:
    最近的一些心理活动
    object_c函数多个返回值
    nslayoutConstraint
    判断一些常用的东西
    color 的一些处理
    最近的心理活动
    加载不同的nib文件
    Be a person
    按钮居左显示
    SQLite错误码
  • 原文地址:https://www.cnblogs.com/lrr0618/p/5364834.html
Copyright © 2011-2022 走看看