Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1332|回复: 0
打印 上一主题 下一主题

win32 sdk下日期时间的相互转换

[复制链接]

1228

主题

1996

帖子

7572

积分

认证用户组

Rank: 5Rank: 5

积分
7572
跳转到指定楼层
楼主
发表于 2019-12-31 12:10:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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;
                                                //////////////////////////////////////////////

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-4-25 12:51 , Processed in 0.054962 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表