因为用到,写了这个函数,先记在这,可能还用的上
int ConvertIntToDateTimeString(int nDate,int nTime,char * strDateTime){ char strBuff[25]; if(nDate>0 && nTime>0) { itoa(nDate,strBuff,10); if(strlen(strBuff)!=8) return 0; itoa(nTime,strBuff,10); if(strlen(strBuff)!=6) return 0; int nYear=0,nMonth=0,nDay=0, nHour=0,nMin=0,nSec=0; nYear=nDate; nHour=nTime; nDay=nYear0; nYear/=100; nMonth=nYear0; nYear/=100; nSec=nHour0; nHour/=100; nMin=nHour0; nHour/=100; memset(strBuff,0,sizeof(strBuff)); sprintf(strBuff,"d-d-d d:d:d",nYear,nMonth,nDay,nHour,nMin,nSec); if( nYear >=1900 && nYear <=9999 && nMonth>=1 && nMonth <=12 && nDay >=1 && nDay <=31 && nHour >=0 && nHour <=23 && nMin >=0 && nMin <=60 && nSec >=0 && nSec <=60 ) { strcpy(strDateTime,strBuff); return 1; } } return 0;}
调用示例:char strRet[25]={0};ConvertIntToDateTimeString(20110309,150225,strRet);
转载于:https://www.cnblogs.com/forads/archive/2011/03/10/2161098.html