×
单片机 > 单片机程序设计 > 详情

STM32中time.h文件详解

发布时间:2020-08-21 发布时间:
|

STM32的time.h文件有时间结构体的定义和时间转化的相关函数。


struct tm {

    int tm_sec;   /* seconds after the minute, 0 to 60

                     (0 - 60 allows for the occasional leap second) */

    int tm_min;   /* minutes after the hour, 0 to 59 */

    int tm_hour;  /* hours since midnight, 0 to 23 */

    int tm_mday;  /* day of the month, 1 to 31 */

    int tm_mon;   /* months since January, 0 to 11 */

    int tm_year;  /* years since 1900 */

    int tm_wday;  /* days since Sunday, 0 to 6 */

    int tm_yday;  /* days since January 1, 0 to 365 */

    int tm_isdst; /* Daylight Savings Time flag */

    union {       /* ABI-required extra fields, in a variety of types */

        struct {

            int __extra_1, __extra_2;

        };

        struct {

            long __extra_1_long, __extra_2_long;

        };

        struct {

            char *__extra_1_cptr, *__extra_2_cptr;

        };

        struct {

            void *__extra_1_vptr, *__extra_2_vptr;

        };

    };

};



上一篇RTC的代码实现文章中有一句Net_time = localtime(&local_timestamp)便是调用了time.h文件中的localtime函数,将秒计数值转换为当前的时间。 



各函数的调用效果可参考链接:time.h 

若想打印出严格的时间格式输出,可采用%02d,如1小时3分5秒可以打印出01:03:05,前面自动补零。实现语句为 

printf(“%d-%02d-%02d %02d:%02d:%02d\r\n”,\ 

Net_time->tm_year+1900, Net_time->tm_mon+1, Net_time->tm_mday,\ 

Net_time->tm_hour,Net_time->tm_min,Net_time->tm_sec); 




『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
C51 特殊功能寄存器SFR的名称和地址