c语言获取系统当前时间的代码:
#include<stdio.h>
#include<time.h>
int main()
{
struct tm *p;
time_t T;
char t[50];
time(&T);
p= localtime(&T);
sprintf(t,"%4d-%.2d-%.2d %2d:%2d:%02d",p->tm_year +1900,p->tm_mon + 1, p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);//年,月,日,时,分,秒
printf("%s\n",t);
return 0;
}
时间: 2024-10-25 12:57:08