# 怎么将一个日期加上多少秒(如45秒)得到一个新的日期

www.MyException.Cn  网友分享于：2013-02-12  浏览：33次

------解决方案--------------------
mktime
------解决方案--------------------
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};

mktime
Converts the local time to a calendar value.

time_t mktime( struct tm *timeptr );
Example

/* MKTIME.C: The example takes a number of days
* as input and returns the time, the current
* date, and the specified number of days.
*/

#include <time.h>
#include <stdio.h>

void main( void )
{
struct tm when;
time_t now, result;
int days;

time( &now );
when = *localtime( &now );
printf( "Current time is %s\n ", asctime( &when ) );
printf( "How many days to look ahead: " );
scanf( "%d ", &days );

when.tm_mday = when.tm_mday + days;
if( (result = mktime( &when )) != (time_t)-1 )
printf( "In %d days the time will be %s\n ",
days, asctime( &when ) );
else
perror( "mktime failed " );
}

------解决方案--------------------
TDateTime dt = StrToDateTime( "2007-1-1 12:00:00 ");
dt = dt + 45.0 * (1 / 24.0 / 60.0 / 60.0);
ShowMessage(DateTimeToStr(dt));
------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

#include <dateutils.hpp>

DateUtils里包含非常丰富的日期时间处理函数
------解决方案--------------------

------解决方案--------------------

------解决方案--------------------
IncSecond好
------解决方案--------------------
#include "DateUtils.hpp "

IncSecond(dt1,Value);

// value 可以是整数 就是 增加,负数就是 减
------解决方案--------------------
good
------解决方案--------------------

------解决方案--------------------
TDateTime dt = StrToDateTime( "2007-1-1 12:00:00 ");