我在
CString
有个约会:"20240415"
。我怎样才能将其解析为COleDateTime
?我的目标是将其格式化为短日期。
我尝试过:
COleDateTime lastInstalledDate;
if (lastInstalledDate.ParseDateTime(strInstallDate, VAR_DATEVALUEONLY, LANG_USER_DEFAULT))
{
strInstallDate = lastInstalledDate.Format(VAR_DATEVALUEONLY);
}
但结果仍然是:
"20240415"
而不是"15/04/2024"
。
这有效:
CString strInstallDate = L"20240415";
const auto longInstallDate = _ttol(strInstallDate);
const auto nYear = longInstallDate / 10000;
const auto nMonth = (longInstallDate / 100) % 100;
const auto nDay = longInstallDate % 100;
COleDateTime datInstallDate;
datInstallDate.SetDateTime(nYear, nMonth, nDay, 0, 0, 0);
CString strFormattedInstallDate = datInstallDate.Format(VAR_DATEVALUEONLY);