温馨提示×

linux strftime能显示星期吗

小樊
85
2025-01-01 18:23:53
栏目: 智能运维
Linux服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

是的,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() 函数将本地时间结构转换为可读的字符串,其中包含星期几的信息。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:linux strftime支持哪些格式

0