0

I am working on an embedded system. Our platform is 32-bit so time_t size is 32-bit.

For now I want to send a struct to a Windows 7 computer as a char array. One of fields of my struct is 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.

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.

So is there any way to conversion?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Murat
  • 803
  • 4
  • 15
  • 27
  • 1
    [https://www.google.se/search?sugexp=chrome,mod=3&sourceid=chrome&ie=UTF-8&q=How+to+convert+32+bit+time_t+value+to+64+bit+time_t ](google) your own headline :-) – Fredrik Pihl Jun 27 '12 at 09:27
  • I think this might help you.. http://stackoverflow.com/questions/2467418/portable-way-to-deal-with-64-32-bit-time-t – khushalbokadey Jun 27 '12 at 09:29
  • `Our platform is 32-bit so time_t size is 32-bit` that's not true. The OS bitness has nothing to do with the size of `time_t`. It's just that previously `time_t` was usually defined to have the same size as the register size. 32-bit Windows has already used 64-bit `time_t` for a long time, and Linux [has just moved to 64-bit `time_t` recently](https://stackoverflow.com/a/60709400/995714) – phuclv Nov 28 '20 at 00:47
  • `because 32-bit time_t starts from year 1970 but 64-bit start from year 1600` is also **completely wrong**. Either 32 or 64-bit `time_t` usually uses the 1970 epoch. Only [Windows FILETIME](https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime) starts from 1601. Those are different types of time and there are [not only 2 of them](https://en.wikipedia.org/wiki/Epoch_(computing)#Notable_epoch_dates_in_computing) – phuclv Nov 28 '20 at 00:51

2 Answers2

2

see: time, _time32, _time64 documentation

Both start at January 1, 1970. You only have to worry about endianness when sending it as chars.

Hubert
  • 149
  • 11
0

Is the precision, i.e. 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.

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 * 1010 seconds".

unwind
  • 391,730
  • 64
  • 469
  • 606
  • `I tried Wolfram Alpha but I don't know how to get a more precise answer than "1.168 * 1010 seconds".` I know what you mean. I tried using AccountingForm, but that didn’t work. And oddly enough, there does not seem to be any information about [preventing scientific notation](https://www.google.com/search?q=prevent+wolfram+alpha+scientific+notation) or [controlling the number format of WA’s results](https://www.google.com/search?q=wolfram+alpha+results+number+format). I guess it’s just not popular enough to get that sort of attention. – Synetech Dec 21 '15 at 02:41