您的位置:首页 > 其它

获取当前日期下一天的公历年月日

2018-02-05 09:54 399 查看
//获取当前日期下一天的公历年月日
static void get_next_date_str(char *current_date_str, char *next_date_str)
{
int32_t n = atoi(current_date_str);
LOG_INFO("current_date_int:%d,", n);

int32_t temp_year = n/10000;
int32_t temp_month = (n%10000)/100;
int32_t temp_day = (n%10000)%100;

LOG_INFO("temp_year:%d,", temp_year);
LOG_INFO("temp_month:%d,", temp_month);
LOG_INFO("temp_day:%d,", temp_day);

if ((temp_month == 4)||(temp_month==6)||(temp_month==9)||(temp_month==11)) //小月处理
{
if (temp_day ==30)
{
temp_day =1;
temp_month++;
}
else
{
temp_day++;
}
}
else if ((temp_month == 1)||(temp_month==3)||(temp_month==5)||(temp_month==7)||(temp_month==8)||(temp_month==10))  //大月处理
{
if (temp_day==31)
{
temp_day =1;
temp_month++;
}
else
{
temp_day++;
}
}
else if (temp_month==12)          //跨年处理
{
if (temp_day==31)
{
temp_year++;
temp_month=1;
temp_day=1;
}
else
{
temp_day++;
}
}
else if (temp_month==2)       //2月处理(没有处理闰月29天情况)
{
if (temp_day == 28)
{
temp_day=1;
temp_month++;
}
else
{
temp_day++;
}
}

sprintf(next_date_str, "%d%02d%02d", temp_year, temp_month, temp_day);
LOG_INFO("next_date_str:%s,", next_date_str);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: