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
要根据参数的具体内容来进行赋值。不要去瞎猜。根据相关的文档使用相应的函数。
原文链接:https://blog.csdn.net/u012782049/article/details/26808773