![]() On Unix and modern MacOS systems it's seconds since 1970, and for compatibility I think it might be used that way on Windows, too. It's almost always a signed, integral type. When you're trying to do calendar arithmetic using time_t, you naturally have to worry about the type and representation of time_t, which is of course implementation-defined. Nwp mentioned in a comment a very good computerphile video: Problem with Time & Timezones. How would your software deal with that? I'm not even sure that timezone is enough!īTW, I'm not sure that Boost or C++11 can reliably deal with such calendar issues. She had some papers mentioning 13 th december 1919, and other papers mentioning 26 th december 1919, referring to the same date in two different calendars. My late mother was born in 1919, during emigration and the civil war, in a Russian village whose legal system was disputed at that time (Russian revolution did not occur instantly). Julian/ Gregorian calendar transition happened in the XX th century in Russia. ![]() Several good recent free software compilers GCC and Clang/LLVM support that standard (compile with -std=c++11 or -std=gnu++14 if you want GNU extensions & C++14)īTW, your question is much more complex than you believe. You might also consider difftime from the C standard and localtime & mktimeĪnd there are a lot of good other reasons to upgrade to C++11 at least (or C++14 if you can). I recommend using the C++11 std::chrono namespace and standard headers and the standard functions and classes inside them. So my question would be, there is any way to get difference in seconds from dates starting before 1970? I know there are also the Boost libraries but is not a usable solution for me. Although libraries may implement this type using alternative time representations. I know that time_t type manage only dates starting from UTC according with the documentation:įor historical reasons, it is generally implemented as an integral value representing the number of seconds elapsed since 00:00 hours, UTC (i.e., a unix timestamp). Whit the code above the application works fine, but if try to set tm.year negative (to build a date before 1900) the mktime() function return -1 Long seconds = difftime(dateNow, referenceDate) ReferenceDate = mktime(&referenceDateComponent) It prints Device rawtime=1568133906 which is PC localtime Tue 16:45:06 GMT => UTC based rawtime=1568155506 (pc was 1568151907)Īs you can see, the converted device timestamp does not equal PC timestamp.What I would like to do with my simple program is to calculate a difference in seconds between two dates. Printf("Device rawtime=%ld which is PC localtime %s => UTC based rawtime=%ld (pc was %ld)\n", device_rawtime, buf, converted, pc_rawtime) ![]() ![]() The following epoch timestamps were converted to human time via Here is my attempt at converting the 3rd party device localtime based seconds since epoch to UTC based seconds since epoch. How would I take the seconds since epoch provided by the device (in localtime) and convert it to seconds since epoch in UTC? In other words, what the programmatic (in C) way to apply PC timezone settings to a seconds since epoch when that number is in localtime? ![]() Let's assume that the timezone settings (UTC offset and daylight savings specifications) are the same between the PC and this device. This is a problem because, when I print the two timestamps in an interleaved log with timestamps from PC and this device, even though the two clocks show the same localtime, the timestamps are off. I also have a 3rd party network device which provides its time also as seconds from epoch, but it does so using localtime instead of UTC time. In PC code, I get UTC time as seconds since epoch using struct timespec tv ĭouble time = (tv.tv_nsec / 1000000000.0) + tv.tv_sec In my system I have a PC (Linux, in case it matters) which keeps RTC time in UTC, making my localtime timezone specific. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |