将unix时间转换为人类可读的格式 [英] Converting a unix time to a human readable format

查看:132
本文介绍了将unix时间转换为人类可读的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立自己的unix时间为人类可读的转换,我被困住了。



我可以提取一年好,但是一天是证明

  / * 
将01-01-1970之后的32位秒数转换为_SYSTEMTIME结构
* /
static _SYSTEMTIME转换(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;
}

还是有一个我忽略的内置函数? p>

提前感谢。



更新:



...似乎Windows Mobile不支持strftime,时间或本地时间,所以我还是必须自己滚动。 :(

解决方案

您在寻找gmtime吗?

  struct tm * gmtime(const time_t * clock); 

外部声明以及tm结构定义都包含在< time.h>包含文件中。 tm结构至少包括以下字段:

int tm_sec; / * seconds(0 - 60)* /
int tm_min; / *分钟(0 - 59)* /
int tm_hour; / * hours(0 - 23)* /
int tm_mday; / *一月中的某一天(1 - 31)* /
int tm_mon; / * )* /
int tm_year; / * year - 1900 * /
int tm_wday; / *星期几(星期日= 0)* /
int tm_yday; / * - 365)* /
int tm_isdst; / *是夏令时生效吗?* /
char * tm_zone; / *时区名称的缩写* /
long tm_gmtoff; / *以秒为单位* /


I'm building my own unix time to human readable conversion, and I'm stuck.

I can extract the year just fine, but the day is proving too tricky.

/*
   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;
}

Or is there a built-in function that I've overlooked?

Thanks in advance.

UPDATE:

Hmm... it seems Windows Mobile doesn't support strftime, time or localtime, so I'll still have to roll my own. :(

解决方案

Are you looking for 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 */

这篇关于将unix时间转换为人类可读的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆