温馨提示×

linux c怎么获取当前时间

小亿
167
2024-08-12 07:55:32
栏目: 智能运维

在Linux系统中,可以使用time.h头文件中的time()函数来获取当前时间。以下是一个示例代码:

#include <stdio.h> #include <time.h> int main() { time_t currentTime; time(&currentTime); printf("Current time: %s", ctime(&currentTime)); return 0; } 

在上面的示例中,time()函数将当前时间的秒数存储在currentTime变量中,然后使用ctime()函数将时间转换为字符串并打印出来。

0