CDateTimeCtrl與CString類型轉換

// 格式爲:2008-01-01 

CTime StrToTime(CString strTime)
{
    
int nYear,nMonth,nDay;
    sscanf(strTime,
"%d-%d-%d",&nYear,&nMonth,&nDay);
    CTime Time(nYear,nMonth,nDay,
0,0,0);
    
return Time;
}


CString TimeToStr(CDateTimeCtrl
& DateTime)
{
    CTime Time;
    DateTime.GetTime(Time);
    
return Time.Format("%Y-%m-%d");
}

PS:
 SYSTEMTIME Time;
 GetLocalTime(&Time);
//2008-01-01 12:12:12 -> 080101121212
 m_BillNo.Format("%02d%02d%02d%02d%02d",Time.wYear-2000,Time.wMonth,Time.wDay,Time.wHour,Time.wMinute);
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章