0
我有這個問題。將CString日期密鑰轉換爲長密鑰
這是我如何創建一個日期的關鍵:最近
,我創建了一個新的類型的關鍵:
WORD wKey = static_cast<WORD>(CInPlaceDT::GetLongDate(psEvent->datEvent));
的GetLongDate
方法是:
long CInPlaceDT::GetLongDate(COleDateTime timDate)
{
long lDate;
lDate = (timDate.GetYear() * 10000) +
(timDate.GetMonth() * 100) +
timDate.GetDay();
return lDate;
}
上述代碼沒有任何問題。但我現在處於這種情況,我需要採取包含格式化密鑰(日期)的CString
並構建相同的日期long
。目前我這樣做:
if (mapSSEventLocations.GetSize() > 0 && m_mapWOSpecialEvents.GetSize() > 0)
{
// The new SRR format does not use the mapSSEventLocations object anymore.
// So we must migrate what we can across.
POSITION sPos = mapSSEventLocations.GetStartPosition();
while (sPos != nullptr)
{
CString strDate, strLocation;
mapSSEventLocations.GetNextAssoc(sPos, strDate, strLocation);
// We must now find the match
// The key is like this: psEvent->datEvent.Format(_T("%Y-%m-%d"));
POSITION sPos2 = m_mapWOSpecialEvents.GetStartPosition();
while (sPos2 != nullptr)
{
WORD wDate;
CSpecialEvent *pEvent = nullptr;
m_mapWOSpecialEvents.GetNextAssoc(sPos2, wDate, (CObject *&)pEvent);
if (pEvent != nullptr)
{
COleDateTime datEvent;
CInPlaceDT::GetOleDateTime(wDate, datEvent);
CString strThisKey = datEvent.Format(_T("%Y-%m-%d"));
if (strThisKey == strDate)
{
// We got the match
pEvent->SetLocation(strLocation);
break;
}
}
}
}
}
它工作正常。但我想採取strDate
並將其轉換爲wDate
樣式鍵,以便我可以查找該事件。