在C语言中,可以使用time.h头文件中的函数来获取当前日期。以下是一个示例代码:
#include <stdio.h>#include <time.h>int main() { time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); printf("Current date and time: %s", asctime(timeinfo)); return 0;}在上面的示例中,time()函数用来获取当前时间的秒数,并将其存储在rawtime变量中。然后,localtime()函数将rawtime转换为本地时间,并将结果存储在timeinfo结构体中。最后,使用asctime()函数将时间信息转换为字符串,并打印出来。




