gpt4 book ai didi

c++ - 将 unix 时间转换为人类可读的格式

转载 作者:行者123 更新时间:2023-11-28 01:12:37 24 4
gpt4 key购买 nike

我正在构建自己的 unix 时间到人类可读的转换,但我被卡住了。

我可以很好地提取年份,但事实证明这一天太棘手了。

/*
Converts a 32-bit number of seconds after 01-01-1970 to a _SYSTEMTIME structure
*/
static _SYSTEMTIME Convert(unsigned long a_UnixTime)
{
newtime.wMilliseconds = 0;
newtime.wYear = (unsigned long)((float)a_UnixTime / (364.24f * 24.f * 60.f * 60.f));
newtime.wDay = (a_UnixTime - (unsigned long)((float)newtime.wYear * 364.24f * 24.f * 60.f * 60.f)); // returns 65177

return newtime;
}

或者是否有我忽略的内置函数?

提前致谢。

更新:

嗯...Windows Mobile 似乎不支持 strftime、时间或本地时间,所以我还是得自己动手。 :(

最佳答案

你在找 gmtime 吗?

struct tm * gmtime(const time_t *clock);

External declarations, as well as the tm structure definition, are contained in the <time.h> include file. The tm structure includes at least the following fields:

int tm_sec; /* seconds (0 - 60) */
int tm_min; /* minutes (0 - 59) */
int tm_hour; /* hours (0 - 23) */
int tm_mday; /* day of month (1 - 31) */
int tm_mon; /* month of year (0 - 11) */
int tm_year; /* year - 1900 */
int tm_wday; /* day of week (Sunday = 0) */
int tm_yday; /* day of year (0 - 365) */
int tm_isdst; /* is summer time in effect? */
char *tm_zone; /* abbreviation of timezone name */
long tm_gmtoff; /* offset from UTC in seconds */

关于c++ - 将 unix 时间转换为人类可读的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1643200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com