zoukankan      html  css  js  c++  java
  • NEXTDAY

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "com_time.h"
    #include "com_func.h"
    /*
     * Definition of leap year:
    
    
    Rule 1: A year is called leap year if it is divisible by 400.
    For example: 1600, 2000 etc leap year while 1500, 1700 are not leap year.
    Rule 2: If year is not divisible by 400 as well as 100 but it is divisible by 4 then that year are also leap year.
    For example:  2004, 2008, 1012 are leap year.
    */
    int isleapyear(int year)
    {
        if ((year%400 == 0) || ((year%4 == 0) && (year%100 != 0))) {
            printf("The year:%d is a leap year!
    ",year);
            return 1;
        }
        return 0;
    }
    
    
    int istimelegal(int year, int month, int day){
        if(year <= 0 || year >=3000)
        {
            printf("the year is out of range([0-3000]!
    ");
            exit(EXIT_FAILURE);
        }else {
            if(isleapyear(year))
            {
                if(month < 1 || month >12)
                {
                    printf("The month of the leap year is out of range
    !");
                }else {
                    if(month == 2)
                    {
                        if(day > 29)
                        {
                            printf("day:%d is out of range",day);
                            exit(EXIT_FAILURE);
                        }
                    }
                    else{
                        if((day <= 0) || (day > 31))
                        {
                            printf("day:%d is out of range",day);
                            exit(EXIT_FAILURE);
                        }
                    }
    
    
                }
            }else {//not leap year
                if(month == 2)
                {
                    if(day > 28)
                    {
                        printf("The month:%d of the year is out of range
    !",month);
                        exit(EXIT_FAILURE);
                    }
                }else {
                    if((day <= 0) || (day > 31))
                    {
                        printf("day:%d is out of range",day);
                        exit(EXIT_FAILURE);
                    }
    
    
                }
    
    
            }
        }
        return 1;
    
    
    }
    
    
    //2016-05-02
    char *nextday(char *date)
    {
        int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        char str_year[5]={0};
        char str_month[3]={0};
        char str_day[3]={0};
        int year=0;
        int month=0;
        int day=0;
        //strncpy();
        sscanf(date,"%4s-%2s-%2s",str_year,str_month,str_day);
        /*printlog(str_year);
        printlog(str_month);
        printlog(str_day);
        printf("%s-%s,%s%s,%s,%s
    ",str_year,str_month,str_day);*/
        year = atoi(str_year);
        month = atoi(str_month);
        day = atoi(str_day);
        //printf("day:%d-%d-%d
    ",year, month, day);
        if(isleapyear(year))
        {
            days[2] = 29;
        }
        else {
            days[2] = 28;
        }
    
    
        //judge time illegal or not
        istimelegal(year,month,day);
        int i = 0;
        int tmp = 0;
        tmp = month;
        for(i = 1;i < 13;i++)
        {
            if(tmp != i)
            {
                continue;
            }else {
                if(day < days[i])
                {
                    printlog("&&&&&&&&&&");
                    day++;
                }else if(day == days[i]){
                    printlog("0000000");
                    month++;
                    if(month > 12)
                    {
                        printlog("121212122");
                        year++;
                        month %= 12;
                    }
                    printlog("********");
                    day = 1;
    
    
                }else {
                    printlog("@@@@@@@@@@");
                    break;
                }
                /*printlog("&&&&&&&&&&");
                day++;
                printlog("@@@@@@@@@@");*/
            }
        }
    
    
        //printf("day:%d-%d-%d
    ",year, month, day);
        sprintf(date, "%4d-%0d-%0d", year, month, day);
        //printlog(date);
        //printf("%s
    ",date);
    
    
        return date;
    }
    ---------------------------------------------------------------------------------------
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    int main(int argc, char *argv[])
    {
        //char date[]="2016-03-31";
        //char date[]="2016-02-29";
        //char date[]="2016-03-09";
        //char date[]="2016-12-31";
    
    
        //char date[]="2015-03-31";
        char date[]="2015-02-29";
        //char date[]="2015-03-09";
        //char date[]="2015-12-31";
        //printf("%d
    ",isleapyear(2015));
        
        nextday(date);
        
        printlog(date);
        return 0;
    }
  • 相关阅读:
    web网站开发反面教材
    phpstudy 做的后台长时间运行的脚本,设置了脚本运行时间还是40秒就返回500,用的apache2.4.39
    PHP_EOL
    web文件下载,a标签文件下载,php文件下载
    邮件发送
    网站调用qq第三方登录
    微信Pcweb登录简介
    JqueryOn绑定事件方法介绍
    php+ajax文件上传
    php操作数组函数
  • 原文地址:https://www.cnblogs.com/guxuanqing/p/5452676.html
Copyright © 2011-2022 走看看