时间转换问题! char *T_Str = "2010-6-19 17:40:46";求以上时间格转为日历时间(从一个标准时间点到此时的时间经过的秒数),以及秒数转为以上格式的代码,如下:time_t tval= ?????? 由以上格式转换得到; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //转化为CTimeCString strTime="2008-7-2 21:59:11";COleVariant vtime(strTime);vtime.ChangeType(VT_DATE);COleDateTime cOleTime=vtime;SYSTEMTIME systime;VariantTimeToSystemTime(cOleTime, &systime);CTime cTimeFromDB(systime); CTime 转换处理我这写都收集了。http://blog.csdn.net/leitianjun/archive/2010/05/17/5599441.aspx 问题我的程序是在SDK下的,没有使用MCF框架中的CString类,用纯C++代码。 http://www.vimer.cn/2009/10/%E6%97%B6%E9%97%B4time_t%E5%92%8Cstring%E6%A0%BC%E5%BC%8F%E4%BA%92%E8%BD%AC.htmlint API_StringToTimeEX(const string &strDateStr,time_t &timeData){ char *pBeginPos = (char*) strDateStr.c_str(); char *pPos = strstr(pBeginPos,“-”); if(pPos == NULL) { printf(“strDateStr[%s] err \n”, strDateStr.c_str()); return -1; } int iYear = atoi(pBeginPos); int iMonth = atoi(pPos + 1); pPos = strstr(pPos + 1,“-”); if(pPos == NULL) { printf(“strDateStr[%s] err \n”, strDateStr.c_str()); return -1; } int iDay = atoi(pPos + 1); int iHour=0; int iMin=0; int iSec=0; pPos = strstr(pPos + 1,” “); //为了兼容有些没精确到时分秒的 if(pPos != NULL) { iHour=atoi(pPos + 1); pPos = strstr(pPos + 1,“:”); if(pPos != NULL) { iMin=atoi(pPos + 1); pPos = strstr(pPos + 1,“:”); if(pPos != NULL) { iSec=atoi(pPos + 1); } } } struct tm sourcedate; bzero((void*)&sourcedate,sizeof(sourcedate)); sourcedate.tm_sec = iSec; sourcedate.tm_min = iMin; sourcedate.tm_hour = iHour; sourcedate.tm_mday = iDay; sourcedate.tm_mon = iMonth - 1; sourcedate.tm_year = iYear - 1900; timeData = mktime(&sourcedate); return 0;} 自己搞定了,原来不是很难的,有错的请指出!//------------------------------------------------------------------------------time_t MY_StrToDate(char *DateStr){ tm d; sscanf(DateStr,"%d-%d-%d %d:%d:%d",&d.tm_year,&d.tm_mon,&d.tm_mday,&d.tm_hour,&d.tm_min,&d.tm_sec); d.tm_year-=1900; return mktime(&d);}//------------------------------------------------------------------------------char *MY_DateToStr(char *pBuf,time_t tval){ struct tm *TM; TM = localtime(&tval); sprintf(pBuf,"%d-%d-%d %d:%d:%d",TM->tm_year+1900,TM->tm_mon,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec); return pBuf;} MFC显示怎么gif图片? textout如何输出换行 如何把汉字赋给VARIANT变量? SDK 编程如何使用 打开文件窗口和保存文件窗口 能控制gif图片显示的帧吗? 急救!Visul studio.net 2003(6CD) 为何安装失败? vc++做出来的exe文件在窗体的右上方是没有最大化和最小化按钮的,请问怎样实 要显示100多张位图(14*14),有什么好算法,不会产生闪烁感 不知用SDK编的程序,最小是多大的啊! 帮我看看,warning MIDL2039 ? 请教Direct3D 如何转换当前的视点(摄像机) COM的包装类该怎么使用
COleVariant vtime(strTime);
vtime.ChangeType(VT_DATE);
COleDateTime cOleTime=vtime;
SYSTEMTIME systime;
VariantTimeToSystemTime(cOleTime, &systime);
CTime cTimeFromDB(systime);
http://blog.csdn.net/leitianjun/archive/2010/05/17/5599441.aspx
{
char *pBeginPos = (char*) strDateStr.c_str();
char *pPos = strstr(pBeginPos,“-”);
if(pPos == NULL)
{
printf(“strDateStr[%s] err \n”, strDateStr.c_str());
return -1;
}
int iYear = atoi(pBeginPos);
int iMonth = atoi(pPos + 1);
pPos = strstr(pPos + 1,“-”);
if(pPos == NULL)
{
printf(“strDateStr[%s] err \n”, strDateStr.c_str());
return -1;
}
int iDay = atoi(pPos + 1);
int iHour=0;
int iMin=0;
int iSec=0;
pPos = strstr(pPos + 1,” “);
//为了兼容有些没精确到时分秒的
if(pPos != NULL)
{
iHour=atoi(pPos + 1);
pPos = strstr(pPos + 1,“:”);
if(pPos != NULL)
{
iMin=atoi(pPos + 1);
pPos = strstr(pPos + 1,“:”);
if(pPos != NULL)
{
iSec=atoi(pPos + 1);
}
}
}
struct tm sourcedate;
bzero((void*)&sourcedate,sizeof(sourcedate));
sourcedate.tm_sec = iSec;
sourcedate.tm_min = iMin;
sourcedate.tm_hour = iHour;
sourcedate.tm_mday = iDay;
sourcedate.tm_mon = iMonth - 1;
sourcedate.tm_year = iYear - 1900;
timeData = mktime(&sourcedate);
return 0;
}
time_t MY_StrToDate(char *DateStr)
{
tm d;
sscanf(DateStr,"%d-%d-%d %d:%d:%d",&d.tm_year,&d.tm_mon,&d.tm_mday,&d.tm_hour,&d.tm_min,&d.tm_sec);
d.tm_year-=1900;
return mktime(&d);
}
//------------------------------------------------------------------------------
char *MY_DateToStr(char *pBuf,time_t tval)
{
struct tm *TM;
TM = localtime(&tval);
sprintf(pBuf,"%d-%d-%d %d:%d:%d",TM->tm_year+1900,TM->tm_mon,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec);
return pBuf;
}