64-bit Unix timestamp conversion

后端 未结 5 1861
野趣味
野趣味 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:44

    The function converting a struct tm* to a time_t is mktime. You can find many implementations of it, eg. in Glibc and in libvxc's mktime.c file. You could take the code (assuming it is legal to you, so please respect licenses) and change time_t to some 64 bits integer like int64_t.

    The functions doing the other conversions from time_t to struct tm* are localtime or gmtime and you could do likewise.

    However, you might have a more fundamental issue: your 32 bits machine running in the year 2040 should have some way of giving you the current time (as the time system call does) appropriately in the 64 bits variant of time_t, and that is much harder (it depends upon the kernel and the hardware).

提交回复
热议问题