http://www.cplusplus.com/reference/ctime/strftime/
/* strftime example */
#include <stdio.h> /* puts */
#include <time.h> /* time_t, struct tm, time, localtime, strftime */
int main ()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,80,"Now it's %I:%M%p.",timeinfo);
puts (buffer);
return 0;
}Now it's 03:21PM.

本文介绍了一个简单的C++程序示例,使用strftime函数将当前时间格式化为易读的字符串。程序首先获取当前时间,然后利用localtime将其转换为本地时间,并最终通过strftime函数将时间格式化为指定的格式。
306

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



