今天 調程序的時候開始一直以爲CTime 類 的Format函數和CDateTimeCtrl類的SetFormat函數的參數形式是一樣的。結果被坑的不行。現將說明如下:
CTime類的Format函數參數形式
常用參數:
%Y:表示年,(大寫)
%m:表示月。(注意是小寫的m)
%d:表示天。(注意是小寫的d)
%H:表示小時。(大寫)
%M:表示分鐘。(大寫)
例子:
CDateTimeCtrl m_CurrentTime;
CTime CurrentTime; //CTime對象
m_CurrentTime.GetTime(CurrentTime);
CurrentTime.Format("%Y-%m-%d %H:%M");
顯示:2014-5-24 09:58
CTime的Format函數的其他參數解釋:
%a
Abbreviated weekday name
%A
Full weekday name
%b
Abbreviated month name
%B
Full month name
%c
Date and time representation appropriate for locale
%d
Day of month as decimal number (01 – 31)
%H
Hour in 24-hour format (00 – 23)
%I
Hour in 12-hour format (01 – 12)
%j
Day of year as decimal number (001 – 366)
%m
Month as decimal number (01 – 12)
%M
Minute as decimal number (00 – 59)
%p
Current locale's A.M./P.M. indicator for 12-hour clock
%S
Second as decimal number (00 – 59)
%U
Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w
Weekday as decimal number (0 – 6; Sunday is 0)
%W
Week of year as decimal number, with Monday as first day of week (00 – 53)
CDateTimeCtrl類SetFormat函數參數
常用參數:
yyyy表示用四位數來表示年。
MM表示用兩位來表示月。 (月用大寫的MM表示)
HH表示小時。
mm表示分鐘。
CDateTimeCtrl *CurrentTime=(CDateTimeCtrl *)GetDlgItem(IDC_CURRENTDATETIME); //CDateTimeCtrl 對象
CurrentTime->SetFormat("yyyy-MM-dd HH:mm");
顯示:2014-05-24 10:04
要根據參數的具體內容來進行賦值。不要去瞎猜。根據相關的文檔使用相應的函數。