将年月日 转换为时间戳;
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); }