64-bit Unix timestamp conversion

后端 未结 5 1844
野趣味
野趣味 2020-12-16 18:00

Is there any C++ implementation of 64-bit Unix timestamp conversions for 32-bit systems? I need to convert struct tm to 64-bit integer and vice versa, including

5条回答
  •  遥遥无期
    2020-12-16 18:49

    You seem to be making the assumption that time_t is 32-bits on 32-bit systems, and this may or may not be true.

    On Windows, starting with Visual Studio 2005 the size of time_t is 64-bits, even when you compile for 32-bit Windows.

    The unfortunate part is that glibc defines it as long int, which on 32-bit systems is a 32-bit integer. That means that 32-bit Linux and other 32-bit platforms that are based on gcc/glibc (like Cygwin) will not be able to work with 64-bit timestamps.

    If your application must run on 32-bit glibc, then you should use your own conversion functions, which could be the same functions in the C library recompiled to use 64-bit timestamps.

    If you need source code with a permissive license (BSD), then you can look at these functions in minix3. Here is localtime. The source is hyperlinked, so you can find the others easily.

提交回复
热议问题