楼上还没有考虑到闰年的问题,
你的参考起始时间很难顾及到闰年的问题,
例如,你选2009年1月1日,
那么2011年1月1日跟它相差多少天呢?还是要考虑到2010年不是闰年.
还是楼主老土一点的办法好一点,
不过感觉将天,小时合并一下好一点.
分别算出sys_time, task_time的下面4个值,
年 unsigned int year;
日 unsigned int f_date(); //当天在当年的第几天
小时 unsigned char hour;
秒 unsigned int f_sec() = minute*60 +second;
char year_c = year[sys] - year[task]; // -1 ~ +1
int date_c = f_date(sys) - f_date(task); // -365 ~ +365
char hour_c = hour[sys] - hour[task]; // -23 ~ +23
int second_c = f_sec[sys] - f_sec[task]; // -3599 ~ +3599
if(year_c >= 0)
{
if(date_c >= 0)
{
if(hour_c >= 0)
{
........
}
}
要考虑到各种情况....
例如 year_c = 1, date_c = -365 这种情况
即sys_time = 2010- 01-01 00:01
task_time = 2009- 12-31 23:59
|