strftime,是一种计算机函数,strftime() 函数根据区域设置格式化本地时间/日期,函数的功能将时间格式化,或者说格式化一个时间字符串。
这里又时间的输出格式 %Y %m %d %H %M %S
#include <stdio.h>
#include <time.h>
int main() {
time_t tt;
char tmpbuf[80];
tt=time(NULL);
strftime(tmpbuf,80,"%Y-%m-%d %H:%M:%S\n",localtime(&tt));
printf(tmpbuf);
return 0;
}
高级点的:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main() {
system("title current time");
system("color E1");
time_t tt;
char tmpbuf[80];
while(1){
system("cls");
tt=time(NULL);
printf("current time: ");
strftime(tmpbuf,80,"%Y-%m-%d %H:%M:%S\n",localtime(&tt));
printf(tmpbuf);
}
return 0;
}