CTime COleTime与CString的转换

一.时间作为特定的数据类型,转换为CString,代码如下:

CString strTime;
extern COleTime time1;
strTime = time1.Format(_T("%Y-%m-%d %H:%M:%S"))

  

关于字符串"%Y-%m-%d %H:%M:%S"的说明:


1. 在MSDN对strftime()函数的说明里,详细解释了各字母代表的含义:

a. %Y Year with century, as decimal number
b. %m Month as decimal number (01 – 12)
c. %d Day of month as decimal number (01 – 31)
d. %H Hour in 24-hour format (00 – 23)
e. %M Minute as decimal number (00 – 59)
f.  %S Second as decimal number (00 – 59)

2.中间的横线或者冒号,都会被原封不动的当成字符串显示出来。采取这些符
号,是因平时时间就是这样来表示的,如:2011-11-11 11:11:11

3. 上面这个字符串的组合基本代表了最普遍的需求。如果程序实在有特殊格
式需求,可以查阅MSDN strftime()项。


二. 将一段文字转换为时间,代码如下:

COleDateTime time1;
time1.ParseDateTime(_T("2011-11-11"));

  

posted on 2011-11-10 17:29  LateStop  阅读(875)  评论(0)    收藏  举报

导航