首页 > 代码库 > VC++ CTime Format 详解
VC++ CTime Format 详解
参考链接:
VC++中CTime类Format参数详解
CTime/COleDateTime::Format方法的使用
http://stat.ethz.ch/R-manual/R-devel/library/base/html/strptime.html
http://www.geezer.org/sw/mvform/doc/strftime.txt
CTime::Format主要用来格式化日期和时间。
举例:
CTime ctNow=CTime::GetCurrentTime(); CString strTime1 = ctNow.Format(_T("%Y年%m月%d日")); // 2014年05月27日 CString strTime2 = ctNow.Format(_T("%Y-%m-%d %H:%M:%S")); // 2014-05-27 14:24:45 CString strTime3 = ctNow.Format(_T("%Y-%#m-%#d %H:%M:%S")); // 2014-5-27 14:24:45 CString strTime4 = ctNow.Format(_T("%c")); // 05/27/14 14:24:45
格式化的参数详细列举如下:
Formats | Description | Memo/Example |
%a | abbreviated weekday name | 星期的缩写 |
%A | full weekday name | 完整的星期名 |
%b | abbreviated month name | 月份的缩写 |
%B | full month name | 完整的月份名 |
%c | locale‘s date and time representation | 当前区域(设置)的日期和时间, 如,05/27/14 13:42:43 |
%d | the day of the month as a decimal number (01-31) | 日 如,27 |
%H | the hour (24-hour clock) as a decimal number(00-23) | 24小时制的小时(00-23) |
%I | the hour (12-hour clock) as a decimal number(01-12) | 12小时制的小时(00-12) |
%j | the day of the year as a decimal number (001-366). | 一年的第几天 如,147 |
%m | the month as a decimal number (01-12). | 月份(00-12) 如,05 |
%M | the minute as a decimal number (00-59). | 分钟(00-59) |
%p | locale‘s equivalent of ``AM‘‘ (ante meridiem) or ``PM‘‘ (post meridiem) as appropriate | PM 或者 AM |
%S | the second as a decimal number (00-60) | 秒钟(00-59) |
%U | the week number of the year (the first Sunday as the first day of week 1) as a decimal number (00-53). | 一年的第几周(周日是第一周的第一天) |
%w | the weekday (Sunday as the first day of the week) as a decimal number (0-6). | 工作日(0-6,周日是一周的第一天) |
%W | the week number of the year (the first Monday as the first day of week 1) as a decimal number (00-53). | 一年的第几周(周一是第一周的第一天) |
%x | locale‘s date representation | 当地区域的日期 如,05/27/2014 |
%X | locale‘s time representation | 当地区域的时间 如,13:54:12 |
%y | the year without century as a decimal number (00-99). | 年(00-99) 如, 14 |
%Y | the year with century as a decimal number. | 年 如,2014 |
%Z | the time zone name | 时区名称 如,China Standard Time |
月份的全称和缩写: 星期的全称和缩写:
Full Month Name | Abbreviated Month Name |
January | Jan |
February | Feb |
March | Mar |
April | Apr |
May | May |
June | Jun |
July | Jul |
August | Aug |
September | Sep |
October | Oct |
November | Nov |
December | Dec |
Full Weekday Name | Abbreviated Weekday Name |
Sunday | Sun |
Monday | Mon |
Tuesday | Tue |
Wednesday | Wed |
Thursday | Thu |
Friday | Fri |
Saturday | Sat |
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。