zoukankan      html  css  js  c++  java
  • 当前日期的 第二天

     NSCalendar *calendar = [[NSCalendaralloc] initWithCalendarIdentifier:NSGregorianCalendar];

        NSDate *now = [NSDate date];

    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |

    NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;

    NSDateComponents *comps  = [calendar components:unitFlags fromDate:now];

    int year = [comps year];

        BOOL isLeapYear = NO ;

        if ((year%4==0&&year%100!=0)||year%400==0) {

            isLeapYear = YES;

        }

        int month = [comps month];

        int monthDay ;

      

            switch (month) {

                    case 1:

                        monthDay = 31;

                        break;

                    case 2:

                    {

                        if (isLeapYear) {

                            monthDay = 29;

                        }

                        monthDay = 28;

                    }

                        break;

                    case 3:

                        monthDay = 31;

                        break;

                    case 4:

                        monthDay = 30;

                        break;

                    case 5:

                        monthDay = 31;

                        break;

                    case 6:

                        monthDay = 30;

                        break;

                    case 7:

                        monthDay = 31;

                        break;

                    case 8:

                        monthDay = 31;

                        break;

                    case 9:

                        monthDay = 30;

                        break;

                    case 10:

                        monthDay = 31;

                        break;

                    case 11:

                        monthDay = 30;

                        break;

                    default:

                        monthDay = 31;

                        break;

            }

        

     

        int today = [comps day];

        int tomorrow = today +1;

     

        if (tomorrow > monthDay && month < 12) {

            month = month +1;

            tomorrow = 1;

        }

        if (tomorrow >monthDay && month == 12) {

            year = year +1;

            month = 1;

            tomorrow = 1;

        }

       

        

    int nowweek = [comps weekday];

        NSString *nowweekstr;

     

        //將星期的數字轉為字串,181010110101,191010110101

        switch (nowweek)

        {

            case 1:

                nowweekstr=@"星期一";

                break;

            case 2:

                nowweekstr=@"星期二";

                break;

            case 3:

                nowweekstr=@"星期三";

                break;

            case 4:

                nowweekstr=@"星期四";

                break;

            case 5:

                nowweekstr=@"星期五";

                break;

            case 6:

                nowweekstr=@"星期六";

                break;

            case 7:

                nowweekstr=@"星期日";

                break;

                

        }

        NSString *dateString = [NSString stringWithFormat:@"%d%d%d          %@",year,month,tomorrow,nowweekstr];

  • 相关阅读:
    PHP xml_get_current_column_number() 函数
    PHP xml_get_current_byte_index() 函数
    PHP xml_error_string() 函数
    PHP utf8_encode() 函数
    PHP utf8_decode() 函数
    MySQL 资料库概论与MySQL 安装
    SEO之网站关键词的优化 :首页,内页关键字,长尾关键字
    前端开发chrome console的使用 :评估表达式 – Break易站
    chrome console的使用 : 异常和错误的处理 – Break易站
    SEO的基本概念 和 提交SITEMAP到搜索引擎
  • 原文地址:https://www.cnblogs.com/guligei/p/3012558.html
Copyright © 2011-2022 走看看