📅  最后修改于: 2020-09-25 09:22:46             🧑  作者: Mango
strftime() 函数在
size_t strftime( char* str, size_t count, const char* format, const tm* time );
strftime() 函数采用4个参数: str
, count
, format
和time
。
通过指向的日期和时间信息time
被转换成基于所述值的空终止多字节字符 format
,并存储由指向阵列中str
。在大多数count
字节写入。
#include
#include
using namespace std;
int main()
{
time_t curr_time;
tm * curr_tm;
char date_string[100];
char time_string[100];
time(&curr_time);
curr_tm = localtime(&curr_time);
strftime(date_string, 50, "Today is %B %d, %Y", curr_tm);
strftime(time_string, 50, "Current time is %T", curr_tm);
cout << date_string << endl;
cout << time_string << endl;
return 0;
}
运行该程序时,输出为:
Today is April 21, 2017
Current time is 11:20:42