我写了一个函数,大致
struct tm when ;
time_t t;
char str1[40],str2[40],strData[40]="20030220";memcpy(str1,strData,4);
when.tmyear = atoi(str1);
...t.tDate = mktime(&when);t.tDate总是-1???
struct tm when ;
time_t t;
char str1[40],str2[40],strData[40]="20030220";memcpy(str1,strData,4);
when.tmyear = atoi(str1);
...t.tDate = mktime(&when);t.tDate总是-1???
解决方案 »
- 从过注册表来添加一个IP地址为可信站点后,如何做到不重启IE立即生效呢?(高分,坐等结贴)
- appbar通知消息怎么延迟超过5秒?
- 对话框获得MainFrame指针
- VC新手提问急
- 紧急求救:xxxx.obj : error LNK2005
- 书上这句话不能理解
- 急急!!抖动问题?
- 我用的同步的CSocket类,发心跳包来判断对方是否断开.如果发送返回的字节数不对是不是先mysocket.close.再mysocket.connet
- 关于构造函数的一个问题?
- 怎样把CString转化为string??急!!
- 关于ODBC访问access2000中m_strSort的问题
- 当Socket的Client端的数目大于5个时,该怎么办?
#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" );
}
mktime()返回值,应该是t,而不是t.tDate
time_t t;
char str1[40],str2[40],strData[40]="20030220";memcpy(str1,strData,4);
when.tmyear = atoi(str1);
...t = mktime(&when);t总是-1就是楼上说的t
???
#define LASTDAY 20030220
int get;
TCHAR day[12];
CTime date;
int year,month,day;
date = CTime::GetCurrentTime();
year = date.GetYear();
month = date.GetMonth();
day = date.GetDay();
sprintf(day,"%d%02d%02d",year,month,day);
get = atoi(day);
year=0;
year=atoi(str1);
when.tmyear = year-1900;
...
t=mktime(&when);
//这样上面t的值肯定不会为-1啦!
sprintf(str2,"%04d%02d%02d",1900+t.tm_year,t.tm_mon+1,t.tm_mday);