怎样得到当前日期加上100天的日期??

zhanghf 2004-01-14 02:21:51
在vc sdk中的编程。

char* tem=NULL;
struct tm when;
__time64_t now;
int days=100;
_time64( &now );
when = *_localtime64( &now );

when.tm_mday = when.tm_mday + days;
tem=asctime( &when ) ;

tem得到的是只把月累加的结果(104天),没有因为过了31而进位,月和年都没有改变!

怎样才能得到正确的日期??
...全文
54 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
masterz 2004-01-15
  • 打赏
  • 举报
回复
Boost is handy.
#include "boost/date_time/gregorian/gregorian.hpp"
using namespace boost::gregorian;
date year_start = date(2004,01,15);
typedef boost::date_time::day_functor<date> add_day;
add_day mf( 100);
date d2 = year_start + mf.get_offset(year_start);
rtdb 2004-01-14
  • 打赏
  • 举报
回复
_time64( &now );
when = *_localtime64( &now );
when.tm_mday = when.tm_mday + days;

改为
_time64( &now );
now += 100 * 24 * 60 * 60 ;
when = *_localtime64( &now );
grooving 2004-01-14
  • 打赏
  • 举报
回复
up!

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧