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);
上一篇:STM32—printf函数重定义
下一篇:STM32—cubeMX+HAL库的SPI接口使用
推荐阅读最新更新时间:2024-03-16 16:23