c语言__Display the current time

#include <stdio.h>
#include <stdlib.h>
#include <time.h>



int main(void)
{
 char m[40];//存放timfo转换过来的字符。asctime_s()需要的变量。
 time_t t;
 struct tm *timfo;
 timfo = (struct tm *)malloc(sizeof(struct tm));
 time(&t);
 localtime_s(timfo,&t);
 printf("%d年%d月%d日%d时%d分%d秒\n", timfo->tm_year + 1900, timfo->tm_mon + 1, timfo->tm_mday, timfo->tm_hour, timfo->tm_min, timfo->tm_sec);
 //-------Method two-----------------------------------------------------
 asctime_s(m, timfo);//转换好的时间,按特定格式放入字符数组中。
 printf("current time :%s",m);//打印数组就是现实时间了。
 free(timfo);
 getchar();
 getchar();
 return 0;
}

你可能感兴趣的:(c语言__Display the current time)