• 【时间戳】 年月日 转换为时间戳


    将年月日 转换为时间戳;

    CString GetUnixTime(int year, int month, int day)
    {
        unsigned __int64 ftNow;
        SYSTEMTIME time;
        ZeroMemory(&time, sizeof(SYSTEMTIME)),
            time.wYear = year;
        time.wMonth = month;
        time.wDay = day;
        SystemTimeToFileTime(&time, (LPFILETIME)&ftNow);
        __int64 timeStamp = (__int64)((ftNow - 0x019db1ded53e8000) / 10000);//毫秒
    
        CString strValue;
        strValue.Format(L"%I64d", timeStamp);
        return strValue;
    }
    
    
    //时间要转为时间戳 
    //可能的时间格式:2012/1/1  2012-1-1 2012_1_1
    //四位数为年,其他第一个为月,第二位日
    CString GetUnixTime(const wstring& strTime)
    {
        vector<wstring> vecSubString;
        wstring sub;
        for (auto it = strTime.cbegin(); it != strTime.cend(); ++it)
        {
            if (*it != '/' && *it != '-' && *it != '_')
            {
                sub.push_back(*it);
            }
            else
            {
                vecSubString.push_back(sub);
                sub.clear();
            }
        }
        if(!sub.empty())
            vecSubString.push_back(sub);
    
        if (vecSubString.size() != 3)
        {
            LOG_ERROR(L"更新时间 的时间格式不符合要求,如:2012/1/1  2012-1-1");
            assert(false);
            return L"";
        }
    
        int year = 0, month = 0, day = 0;
        for (auto it = vecSubString.cbegin(); it != vecSubString.cend(); ++it)
        {
            if (it->length() == 4)
            {
                year = _ttoi(it->c_str());
            }
            else{
                if (month == 0)
                {
                    month = _ttoi(it->c_str());
                }
                else{
                    day = _ttoi(it->c_str());
                }
            }
        }
    
        return GetUnixTime(year, month, day);
    }
  • 相关阅读:
    java 上传图片
    getElementById 鼠标经过字体改变颜色
    getElementById 学习
    css的绝对定位与相对定位
    关于For循环
    扩展方法的应用
    关于Function 的学习笔记
    <a>标签中查找文件的方法
    关于Name ID class属性的区别
    使用float设置经典的网站前端结构
  • 原文地址:https://www.cnblogs.com/pjl1119/p/8933732.html
Copyright © 2020-2023  润新知