zoukankan      html  css  js  c++  java
  • timestr

    -(void)timeStr

    {

        NSDate *date = [NSDate date];

        NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

        NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

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

        formatter.dateFormat = @"yyyy.MM";

        NSDateComponents *currentComps = [currentCalendar components:unitFlags fromDate:date];

        NSDateComponents *resultComps = [[NSDateComponents alloc]init];

        [resultComps setYear:[currentComps year]];

        [resultComps setMonth:[currentComps month]];

        [resultComps setWeekday:[currentComps weekday]];

        NSInteger mMonth = [currentComps month];

        for(int i =3;i>-1;i--){

            NSInteger uMonth = mMonth - i;

            [resultComps setMonth:uMonth];

            NSDate *returnDate = [currentCalendar dateFromComponents:resultComps];

            NSString *returnStr = [formatter stringFromDate:returnDate];

            NSLog(@"%@",returnStr);

        }

        

    }

     

    2月份的   30日   =  3月份,我日错了

  • 相关阅读:
    linux配置PHP环境!!(云服务器架设)
    JQ上传预览+存数据库
    AJAX做增删改查详细!
    JS解析XML
    UEditor编辑器的使用
    php注释规范
    phpexcel导出数据表格
    简单分析JavaScript中的面向对象
    制作smarty模版缓存文件
    求二叉树中节点的最大距离
  • 原文地址:https://www.cnblogs.com/guligei/p/5336571.html
Copyright © 2011-2022 走看看