time.h中的strftime函数用于把struct tm转换为字符串输出,类似于printf,我们可以为其指定格式,下表是其使用的格式字符
来源:http://www.cplusplus.com/reference/clibrary/ctime/strftime/
| specifier | Replaced by | Example |
|---|---|---|
| %a | Abbreviated weekday name * | Thu |
| %A | Full weekday name * | Thursday |
| %b | Abbreviated month name * | Aug |
| %B | Full month name * | August |
| %c | Date and time representation * | Thu Aug 23 14:55:02 2001 |
| %d | Day of the month (01-31) | 23 |
| %H | Hour in 24h format (00-23) | 14 |
| %I | Hour in 12h format (01-12) | 02 |
| %j | Day of the year (001-366) | 235 |
| %m | Month as a decimal number (01-12) | 08 |
| %M | Minute (00-59) | 55 |
| %p | AM or PM designation | PM |
| %S | Second (00-59) | 02 |
| %U | Week number with the first Sunday as the first day of week one (00-53) | 33 |
| %w | Weekday as a decimal number with Sunday as 0 (0-6) | 4 |
| %W | Week number with the first Monday as the first day of week one (00-53) | 34 |
| %x | Date representation * | 08/23/01 |
| %X | Time representation * | 14:55:02 |
| %y | Year, last two digits (00-99) | 01 |
| %Y | Year | 2001 |
| %Z | Timezone name or abbreviation | CDT |
| %% | A % sign | % |
本文详细介绍了time.h中的strftime函数,该函数可以将struct tm结构体转换为字符串形式,并支持多种日期时间格式化选项。例如,%a代表星期的缩写名称,%Y代表完整的年份等。
1261

被折叠的 条评论
为什么被折叠?



