firemail
标题:
win32 sdk下日期时间的相互转换
[打印本页]
作者:
Qter
时间:
2019-12-31 12:10
标题:
win32 sdk下日期时间的相互转换
char szTimer[20]={0};
int ntimer = 111111;
//字串串日期获取年月日时
int yyyy=0,mm=0,dd=0,hh=0,nn=0,ss=0;
sscanf(szTimer,"%04d%02d%02d%02d%02d%02d",
&yyyy,&mm,&dd,&hh,&nn,&ss);
//整形获取年月日时
time_t cur_time(ntimer);
struct tm * cur_tm = localtime(&cur_time);
int nYear = cur_tm->tm_year + 1900;
int nMonth = cur_tm->tm_mon + 1 ;
int nDay = cur_tm->tm_mday;
int nHour = cur_tm->tm_hour;
//////////////////////////////////
tm tm;
memset(&tm, 0, sizeof(tm));
sscanf(sCountTime, "%04d%02d%02d%02d%02d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
tm.tm_year -= 1900;
tm.tm_mon--;
time_t nTimer = mktime(&tm);
/*nTimer += (nSec + (nMin*60) + (nHour*60*60) + (nDay*24*60*60));
tm = *localtime(&nTimer);
tm.tm_year += 1900;
tm.tm_mon++;
char sBuf[20];
sprintf(sBuf, sFormat, tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);*/
char sCountTime[20]={0};
strcpy(sCountTime,"201206110942");
char szKeyTime[20]={0};
int nYear=0,nMonth=0,nDays=0,nHours=0,nn=0,ss=0;
sscanf(sCountTime,"%04d%02d%02d%02d%02d",&nYear,&nMonth,&nDays,&nHours,&nn,&ss);
sprintf(szKeyTime,"%04d-%02d-%02d %02d:00:00",nYear,nMonth,nDays,nHours);
//解决 8点前数据变成前一天的数据的问题 日期转整形
/////////////////////////////
tm tm;
memset(&tm, 0, sizeof(tm));
tm.tm_year = nYear;
tm.tm_mon = nMonth;
tm.tm_mday = nDay;
tm.tm_hour=0;
tm.tm_min =0;
tm.tm_sec = 0;
tm.tm_year -= 1900;
tm.tm_mon--;
time_t nTimer = mktime(&tm);
nTimer = nTimer + nIntResult;
struct tm * cur_tm_ok = localtime(&nTimer);
nYear = cur_tm_ok->tm_year + 1900;
nMonth = cur_tm_ok->tm_mon + 1 ;
nDay = cur_tm_ok->tm_mday;
nHour = cur_tm_ok->tm_hour;
nMin = cur_tm_ok->tm_min;
nSecond = cur_tm_ok->tm_sec;
//////////////////////////////////////////////
欢迎光临 firemail (http://firemail.wang:8088/)
Powered by Discuz! X3