C语言基础:获得当前日期和时间的代码

240 阅读1分钟

将内容过程中比较好的一些内容段备份一次,如下资料是关于C语言基础:获得当前日期和时间的内容。

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

int main (void) {

time_t seconds;

time(&seconds);

gm_date = gmtime(&seconds);

printf("Current date: %d-%d-%dn", gm_date->tm_mon+1, gm_date->tm_mday, gm_date->tm_year); printf("Current time: %02d:%02dn", gm_date->tm_hour, gm_date->tm_min);

return 1; }

输出结果,GCC编译

Current date: 9-9-112 Current time: 09:16