std::asctime
Defined in header <ctime> | | |
---|---|---|
char* asctime( const std::tm* time_ptr ); | | |
转换给定的日历时间std::tm
以下列固定的25个字符形式的文本表示:Www Mmm dd hh:mm:ss yyyy\n
...
Www
-三字母英语缩写为一周中的第一天time_ptr->tm_wday
,其中之一Mon
,,,Tue
,,,Wed
,,,Thu
,,,Fri
,,,Sat
,,,Sun
...
Mmm
-三字母英语缩写月份名称time_ptr->tm_mon
,其中之一Jan
,,,Feb
,,,Mar
,,,Apr
,,,May
,,,Jun
,,,Jul
,,,Aug
,,,Sep
,,,Oct
,,,Nov
,,,Dec
...
dd
-每月2位数的日子timeptr->tm_mday
好像是由sprintf
使用%2d
hh
-2位数小时timeptr->tm_hour
好像是由sprintf
使用%.2d
mm
-2位数分钟timeptr->tm_min
好像是由sprintf
使用%.2d
ss
-2位数秒timeptr->tm_sec
好像是由sprintf
使用%.2d
yyyy
-4位数的年份timeptr->tm_year + 1900
好像是由sprintf
使用%4d
的任何成员都未定义此行为。*time_ptr
超出了正常范围。
表示的日历年,则此行为未定义。time_ptr->tm_year
有超过4位数或小于1000。
函数不支持本地化,换行符无法删除。
该函数修改静态存储,并且不是线程安全的.
参数
time_ptr | - | pointer to a std::tm object specifying the time to print |
---|
返回值
指向静态空结束字符串的指针,该字符串保存日期和时间的文本表示形式。字符串可以在std::asctime
和std::ctime
,并且可以在每次调用这些函数时覆盖。
注记
此函数返回一个指向静态数据的指针,并且不是线程安全的.。POSIX将此功能标记为过时,并建议std::strftime
相反。
时,POSIX将未定义的行为限制为输出字符串将大于25个字符的时间。timeptr->tm_wday
或timeptr->tm_mon
不在预期范围内,或timeptr->tm_year
超INT_MAX-1990
...
一些实现处理timeptr->tm_mday==0
意思是前一个月的最后一天。
例
二次
#include <ctime>
#include <iostream>
int main()
{
std::time_t result = std::time(NULL);
std::cout << std::asctime(std::localtime(&result));
}
二次
产出:
二次
Mon Apr 3 20:26:26 2017
二次
另见
ctime | converts a time_t object to a textual representation (function) |
---|---|
strftime | converts a tm object to custom textual representation (function) |
put_time (C++11) | formats and outputs a date/time value according to the specified format (function template) |
C升空文件
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com