zoukankan      html  css  js  c++  java
  • 两个获得 年月日 的方法,

    //get day month year week from nsdate

    -(NSString *)dayFromDate:(NSDate *)date

    {

        NSString *dateString;

        NSCalendar*calendar = [NSCalendar currentCalendar];

        NSDateComponents*comps;

        

        comps =[calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit |NSDayCalendarUnit|NSWeekdayCalendarUnit|NSWeekdayOrdinalCalendarUnit)

                           fromDate:date];

        NSInteger year = [comps year];

        NSInteger month = [comps month];

        NSInteger day = [comps day];

        NSLog(@"year:%d month: %d, day: %d", year, month, day);

        NSInteger weekdayNumber = [comps weekday];

        switch (weekdayNumber) {

            case 1:

                weekday = @"星期日";

                break;

            case 2:

                weekday = @"星期一";

                break;

            case 3:

                weekday = @"星期二";

                break;

            case 4:

                weekday = @"星期三";

                break;

            case 5:

                weekday = @"星期四";

                break;

            case 6:

                weekday = @"星期五";

                break;

            default:

                weekday = @"星期六";

                break;

        }

        dateString = [NSString stringWithFormat:@"%d%d%d",year,month,day];

        return dateString;

    }

     

     

     

     NSDate *tomorrow = [NSDatedateWithTimeIntervalSinceNow:86400];//60*60*24 24hours

        NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];

    NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];

        dateFormatter.dateFormat = @"yyyyMMdd";

        NSString *dateStr = [dateFormatter stringFromDate:date];

        

        [self.dateButtonsetTitle:dateStr forState:UIControlStateNormal];

        

        NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];

        dateFormatter2.weekdaySymbols = @[@"星期日", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六"];

        [dateFormatter2 setDateFormat: @"EEEE"];

        NSString *wekday = [dateFormatter2 stringFromDate:date];

  • 相关阅读:
    开启 clr enabled
    索引查看
    nginx 安装
    mysql中int(10)与int(11)有什么区别吗?
    1.安卓开发基础1~6笔记
    Vue项目搭建基础之Vue-cli模版测试
    alert执行顺序
    介绍call和apply
    a链接易混淆与form表单简易验证用法详解
    js正则知识点
  • 原文地址:https://www.cnblogs.com/guligei/p/3025539.html
Copyright © 2011-2022 走看看