美文网首页
c语言获取系统时间

c语言获取系统时间

作者: arkliu | 来源:发表于2022-11-03 09:26 被阅读0次

    struct tm结构体

    image.png
    #include<stdlib.h>
    #include<stdio.h>
    #include<time.h>
    
    int main() {
        time_t cur_time = time(NULL);
        struct tm* timer = localtime(&cur_time);
    
        int year = timer->tm_year + 1900;
        int month = timer->tm_mon+1;
        int day = timer->tm_mday;
        int hour = timer->tm_hour;
        int min = timer->tm_min;
        int second = timer->tm_sec;
        int week = timer->tm_wday; // 0-6
        const char* weeks[] = {"日","一","二","三","四","五","六"};
    
        printf("%d年%d月%d日 %d:%d:%d 星期%s \n", year, month, day, hour, min, second, weeks[week]);
    
        return 0;
    }
    
    image.png

    相关文章

      网友评论

          本文标题:c语言获取系统时间

          本文链接:https://www.haomeiwen.com/subject/pwuetdtx.html