求一函数,实现日期加减,用c写

来源:百度知道 编辑:UC知道 时间:2024/06/16 08:24:42
输入任意日期,格式如2007-2-8,输入天数,如-1、4,返回目标日期。
如function xx(2007-2-2,-7)返回值为2007-1-26。
不要程序了,谁能告诉我最简洁的算法就行了

// sts.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <time.h>

///输入时间 (1970.1.1---3000.12.31),否则无法转换
void convert( char* chOutDate, const char *chInDate, const char* chInc )
{
char dateFormat[40]="";
int inDateLen = (int)strlen(chInDate);

//取出输入日期格式
int l = 0;
for(int i=0; i<inDateLen; )
{
if( chInDate[i] <'0' || chInDate[i] > '9' )
{
dateFormat[l++] = chInDate[i++];
continue;
}

dateFormat[l++] = '%';
dateFormat[l++] = 'd';
++i;

while( chInDate[i]>='0'&& chInDate[i]<='9' )
{
++i;
}
}

//天数
int incDays = 0;
sscanf(chInc, "