如何将一个日期加上多少秒(如45秒)得到一个新的日期?
如何将一个日期加上多少秒(如45秒)得到一个新的日期?
[解决办法]
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));
[解决办法]
这个应该没问题吧?
先获取一个当前时间的SYSTEMTIME,然后将其中的秒数加上你要加的秒数,然后判断是否大于等于60,如果大于的则秒数对60取余,再分数加1;判断分数是否大于等于60...再然后小时数,再然后日期....
[解决办法]
日期其实就是一个double型,安装ccrun那样+就可以了,简单
[解决办法]
干嘛不用现成的函数IncSecond(Now(),20)
#include <dateutils.hpp>
DateUtils里包含非常丰富的日期时间处理函数
[解决办法]
有人答了,我就不答了
[解决办法]
受教,谢谢
[解决办法]
IncSecond好
[解决办法]
#include "DateUtils.hpp "
IncSecond(dt1,Value);
// value 可以是整数 就是 增加,负数就是 减
[解决办法]
good
[解决办法]
学习中
[解决办法]
TDateTime dt = StrToDateTime( "2007-1-1 12:00:00 ");
TDateTime dtAdd(0,0,45,0);
dt += dtAdd;
增加45s。。。
小时、分、微秒都可以这样。。
天的话直接dt += 1;
月和年这个办法不行。。
[解决办法]
look