首页 > 编程语言 > 详细

MFC下北京时间与时间戳相互转换

时间:2021-07-01 15:13:40      阅读:137      评论:0      收藏:0      [点我收藏+]
//时间戳转北京时间字串
CString getLocalDate(__int64 timestamp)
{
    timestamp += 28800;//GTM偏移8个时区得到北京时间
    tm p;
    gmtime_s(&p, &timestamp);
    char s[80];
    strftime(s, 80, "%Y-%m-%d %H:%M:%S", &p);
    return CString(s);
}

//北京时间字串转时间戳
__int64 getTimestamp(CString strInputTime)
{
    COleVariant vtime(strInputTime);
    vtime.ChangeType(VT_DATE);
    COleDateTime cOleTime = vtime;
    SYSTEMTIME systime;
    VariantTimeToSystemTime(cOleTime, &systime);
    //时间戳最小值为北京时间:1970-01-01 08:00:00
    if (systime.wYear <= 1970 && systime.wMonth <= 1 && systime.wDay <= 1 && systime.wHour <= 7 && systime.wMinute <= 59 && systime.wSecond <= 59)
        return 0;
    CTime cTimeFromDB(systime);
    __int64 timestamp = cTimeFromDB.GetTime();//CTime->时间戳
    return timestamp;
}

 

MFC下北京时间与时间戳相互转换

原文:https://www.cnblogs.com/rcg714786690/p/14957927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!