_考不上研究生不改名 2023-01-09 22:43 采纳率: 100%
浏览 40
已结题

struct tm类型

C中的struct tm类型他的成员赋值顺序是什么?年月日时分秒还是时分秒年月日?

  • 写回答

1条回答 默认 最新

  • 生产队的小刘 Python领域新星创作者 2023-01-09 22:48
    关注

    在C中,struct tm 类型用于表示日历时间。它包含如下成员:

    struct tm {
        int tm_sec;   /* 秒,范围从 0 到 59          */
        int tm_min;   /* 分钟,范围从 0 到 59          */
        int tm_hour;  /* 小时,范围从 0 到 23          */
        int tm_mday;  /* 一个月中的第几天,范围从 1 到 31 */
        int tm_mon;   /* 月份,范围从 0 到 11           */
        int tm_year;  /* 自 1900 年起的年数              */
        int tm_wday;  /* 一周中的第几天,范围从 0 到 6   */
        int tm_yday;  /* 一年中的第几天,范围从 0 到 365  */
        int tm_isdst; /* 夏令时,>0 表示夏令时,=0 表示非夏令时,<0 表示未知 */
    };
    

    顺序是:秒、分钟、小时、一个月中的第几天、月份、自1900年起的年数、一周中的第几天、一年中的第几天和夏令时。

    例如,要表示2022年1月2日12时34分56秒,你可以这样赋值:

    struct tm time_structure;
    time_structure.tm_sec = 56;
    time_structure.tm_min = 34;
    time_structure.tm_hour = 12;
    time_structure.tm_mday = 2;
    time_structure.tm_mon = 0; // 0 表示 1 月,1 表示 2 月,依此类推
    time_structure.tm_year = 122; // 122 表示从 1900 年开始的 2022 年
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月17日
  • 已采纳回答 1月9日
  • 创建了问题 1月9日

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序