简体   繁体   English

如何将 32 位 time_t 值转换为 64 位 time_t

[英]How to convert 32 bit time_t value to 64 bit time_t

I am working on an embedded system.我正在研究嵌入式系统。 Our platform is 32-bit so time_t size is 32-bit.我们的平台是 32 位的,所以time_t大小是 32 位。

For now I want to send a struct to a Windows 7 computer as a char array.现在我想将一个结构作为char数组发送到 Windows 7 计算机。 One of fields of my struct is time_t .我的结构的字段之一是time_t I can't change struct.我不能改变结构。

So I must send time value to Windows Machine with a 32-bit variable and when char array arrived I must convert 32 bit unsigned int value to 64-bit time_t .因此,我必须使用 32 位变量将时间值发送到 Windows 机器,当 char 数组到达时,我必须将 32 位 unsigned int 值转换为 64 位time_t

I think I can't convert directly 32-bit integer to 64-bit time_t because 32-bit time_t starts from year 1970 but 64-bit start from year 1600.我想我不能将 32 位整数直接转换为 64 位time_t ,因为 32 位time_t从 1970 年开始,而 64 位从 1600 年开始。

So is there any way to conversion?那么有没有办法转换呢?

see: time, _time32, _time64 documentation请参阅: 时间、_time32、_time64 文档

Both start at January 1, 1970. You only have to worry about endianness when sending it as chars.两者都从 1970 年 1 月 1 日开始。您只需要在将其作为字符发送时担心字节顺序。

Is the precision, ie the unit, the same (seconds)?精度,即单位,是否相同(秒)? If so, then you should be able to convert the larger number by subtracting the difference and truncating to 32 bits.如果是这样,那么您应该能够通过减去差值并截断为 32 位来转换较大的数字。

Computing the required number of seconds might be a bit tricky... I tried Wolfram Alpha but I don't know how to get a more precise answer than "1.168 * 10 10 seconds".计算所需的秒数可能有点棘手……我尝试了Wolfram Alpha ,但我不知道如何获得比“1.168 * 10 10秒”更精确的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM