【MFC】CDateTimeCtrl 空间设置默认日期和时间

控件默认是获取当前的日期和时间的,当需要设置默认日期时间的时候,可以如下操作:

// 绑定空间的成员:

    CDateTimeCtrl m_dateBegin; //日期

    CDateTimeCtrl m_timeBegin;//时间

    COleDateTime  currOleDate;
    m_dateEnd.GetTime(currOleDate);
    COleDateTime oleDate;
    oleDate.SetDate(currOleDate.GetYear() - 1, currOleDate.GetMonth(), currOleDate.GetDay());  
    m_dateBegin.SetTime(oleDate);   
 
    COleVariant vtime("0:00:00");//设定时间控件时间信息
    vtime.ChangeType(VT_DATE);
    COleDateTime oleTime=vtime;
    m_timeBegin.SetTime(oleTime);

CDateTimeCtrl 时间和日期的切换在控件属性里的 Format中选择。
 

    COleDateTime time;

    time = COleDateTime::GetCurrentTime();

    CString str;

    str.Format(TEXT("%04d-%02d-%02d"),time.GetYear(),time.GetMonth(),time.GetDay());

    MessageBox(str.GetBuffer());

m_time.SetFormat(_T("yyyy-MM-dd"));
后显示为2013-05-16
m_time.SetFormat(_T("YYYY-\x4d\x4d-DD"));
显示为2013-05-16
m_time.SetFormat(_T("YYYY-'MM'-DD"));
显示为YYYY-MM-DD
 

猜你喜欢

转载自blog.csdn.net/Pei_hua100/article/details/94430201