MONTH(),DAY()等函数的头文件是什么?
我知道某个时间对已知时间点(比如2015.1.1)的时间差(单位秒),怎么求这个时间点的日期?
程序代码:#include <time.h>
#include <stdio.h>
void foo( int year, int mon, int day
, int hour, int min, int sec
, int delta_sec )
{
struct tm tm1 = { sec,min,hour, day,mon-1,year-1900, 0,0,0 };
time_t t1 = mktime( &tm1 );
if( t1 == time_t(-1) )
{
puts( "[ERROR] ……" );
return;
}
time_t t2 = t1 + delta_sec;
struct tm* tm2 = localtime( &t2 );
if( !tm2 )
{
puts( "[ERROR] ……" );
return;
}
printf( "%04d-%02d-%02d %02d:%02d:%02d\n"
, tm2->tm_year+1900, tm2->tm_mon+1, tm2->tm_mday
, tm2->tm_hour, tm2->tm_min, tm2->tm_sec );
}
int main( void )
{
printf( "%s", "2015-01-01 00:00:00的后3600秒 是 " );
foo( 2015, 1, 1, 0, 0, 0, +3600 );
printf( "%s", "2015-01-01 00:00:00的前3600秒 是 " );
foo( 2015, 1, 1, 0, 0, 0, -3600 );
return 0;
}





