Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将unix时间转换为人类可读的格式_C++_Unix_Time - Fatal编程技术网

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

C++ 将unix时间转换为人类可读的格式,c++,unix,time,C++,Unix,Time,我正在构建自己的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

我正在构建自己的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、time或localtime,所以我还是要自己运行(

你在找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 */
struct tm*gmtime(常数时间时钟);
外部声明以及tm结构定义包含在包含文件中。tm结构至少包括以下字段:
int tm_sec;/*秒(0-60)*/
int tm_min;/*分钟(0-59)*/
国际标准小时;/*小时(0-23)*/
int tm_mday;/*月日(1-31)*/
int tm_mon;/*年度月份(0-11)*/
int tm_年;/*年-1900年*/
int tm_wday;/*一周中的某一天(星期日=0)*/
int tm_yday;/*一年中的某一天(0-365)*/
int tm_isdst;/*夏季有效吗*/
char*tm_zone;/*时区名称的缩写*/
长tm_gmtoff;/*与UTC的偏移量(秒)*/

你在找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 */
struct tm*gmtime(常数时间时钟);
外部声明以及tm结构定义包含在包含文件中。tm结构至少包括以下字段:
int tm_sec;/*秒(0-60)*/
int tm_min;/*分钟(0-59)*/
国际标准小时;/*小时(0-23)*/
int tm_mday;/*月日(1-31)*/
int tm_mon;/*年度月份(0-11)*/
int tm_年;/*年-1900年*/
int tm_wday;/*一周中的某一天(星期日=0)*/
int tm_yday;/*一年中的某一天(0-365)*/
int tm_isdst;/*夏季有效吗*/
char*tm_zone;/*时区名称的缩写*/
长tm_gmtoff;/*与UTC的偏移量(秒)*/

如果你想格式化打印,你需要
,它是标准解决方案,与例如
一起使用,将原始时间戳转换为更人性化的格式。

如果你想格式化打印,你需要
,它是标准解决方案,与例如
一起用于转换原始时间戳p改为更人性化的格式。

如果考虑闰秒,即使秒数也很难。从1970年以来已经有24秒了。如果Windows Mobile没有strftime,我会寻找它可能有的其他东西……我想你可能真的需要自己动手,但我觉得他们肯定提供了一些东西。。。否?(注意:无论是作为用户还是开发人员,我都没有使用Windows Mobile的经验。)如果你考虑到闰秒数,甚至秒数都会很难。从1970年以来,已经有24秒了。如果Windows Mobile没有strftime,我会寻找它可能有的其他东西……我想你可能真的需要自己动手,但我觉得他们肯定提供了一些东西……没有?(注意:无论是作为用户还是开发人员,我都没有使用Windows Mobile的经验。)