温馨提示×

linux strftime能显示星期吗

小樊
95
2025-01-01 18:23:53
栏目: 智能运维

是的,strftime 函数在 Linux 中可以显示星期

#include <stdio.h> #include <time.h> int main() { time_t rawtime; struct tm * timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); printf("Today is %s\n", asctime(timeinfo)); return 0; } 

在这个示例中,我们首先使用 time() 函数获取当前时间,然后使用 localtime() 函数将时间转换为本地时间结构。最后,我们使用 asctime() 函数将本地时间结构转换为可读的字符串,其中包含星期几的信息。

0