原始版本
This commit is contained in:
31
stm32f407vet6_v2/applications/app.c
Normal file
31
stm32f407vet6_v2/applications/app.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <sys/time.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
/**
|
||||
* @brief 测试 timegm 函数,将指定时间转换为时间戳
|
||||
*
|
||||
* 需要注意 tm 结构体的各字段含义:
|
||||
* tm_year: 年份 = 实际年份 - 1900
|
||||
* tm_mon : 月份 = 0~11(1月为0)
|
||||
* tm_mday: 日
|
||||
* tm_hour: 时
|
||||
* tm_min : 分
|
||||
* tm_sec : 秒
|
||||
* tm_isdst: 夏令时标志,0表示不使用夏令时
|
||||
*/
|
||||
void test_timegm(void)
|
||||
{
|
||||
struct tm tm = {0};
|
||||
time_t timestamp;
|
||||
tm.tm_year = 2025 - 1900; // 年份从1900开始
|
||||
tm.tm_mon = 5 - 1; // 月份0-11,5月为4
|
||||
tm.tm_mday = 23;
|
||||
tm.tm_hour = 9;
|
||||
tm.tm_min = 56;
|
||||
tm.tm_sec = 50;
|
||||
tm.tm_isdst = 0; // 不使用夏令时
|
||||
|
||||
timestamp = mktime(&tm);
|
||||
//rt_kprintf("时间戳: %ld\n", (long)timestamp);
|
||||
}
|
||||
MSH_CMD_EXPORT(test_timegm, test timegm function);
|
||||
Reference in New Issue
Block a user