2009-10-29 99 views
0

我建立我自己的UNIX时间以人类可读的转换,我被困。转换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; 
} 

还是有一个内置函数,我忽略了?

在此先感谢。

UPDATE:

嗯......看来,Windows Mobile不支持的strftime,时间或本地时间,所以我还是要推出自己的。 :(

+0

如果你考虑闰秒,甚至几秒钟就会很难 – 2009-10-29 19:20:24

+0

PS。自从1970年以来有24个 – 2009-10-29 19:21:31

+0

如果Windows Mobile没有strftime,我会寻找它可能有的东西。 ..我想这有可能是你必须自己推出的,但它让我觉得有些不适应他们肯定提供的东西*莫名其妙* ...不是? (注意:我对Windows Mobile没有经验,无论是作为用户还是作为开发人员。) – lindes 2011-02-23 08:26:28

回答

2

您是否在寻找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 */ 
1

如果你想格式打印,你需要strftime(),这是标准的解决方案,如localtime()一起使用,以原始时间戳转换为更加人性化

相关问题