c++ - Daylight Saving Time and UTC-to-local time conversions with WinAPIs -
I change what I'm trying to see it in Vindapiai between UTC time and local contrast Daylight Saving Time accurate Ho. For example, take the API. It explains the details:
LocalfileTemplate uses the current settings for the time-zone and daylight saving time. Therefore, if this is a daylight saving time, then this function will account for Daylight Savings Time, even if the time you are changing is in standard time.
So I'm testing it with code:
// If the DST change is March 8-2015 at 2:00 PM In the morning / when the clock is forwarded forward 1 hour / let's check the difference. Between two times: SYSTEMTIME st1_local = {2015, 3, 0, 8, 1, 30, 0, 0}; // March-8-2015 1:30:00 AM systemtime st2_local = {2015, 3, 0, 8, 3, 30, 0, 0}; // Mar-8-2015 3:30:00 AM // Change in file-time format FILETIME ft1_local, ft2_local; Verify (:: SystemTimeToFileTime (& st1_local, & amp; ft1_local)); Verify (:: SystemTimeToFileTime (& st2_local, & amp; ft2_local)); // then change from local to UTC time FILETIME ft1_utc, ft2_utc; Verify (:: localfileTemplateFileTime (& amp; ft1_local, & amp; amp; ft1_utc)); Verify (:: LocalfileTemplateTime (& amp; amp; ft2_local; & amp; ft2_utc)); // Get Long Long iiDiff100ns difference = (((Langlong) ft2_utc.dwHighDateTime & lt; & lt; 32) | ft2_utc.dwLowDateTime) - (((long) ft1_utc.dw Haidtaim & lt; & lt; 32) | ft1_utc.dwLowDateTime; // long long iiDiffSecs = to convert seconds 100ns iiDiff100ns / 10000000LL; // I 1 hour ASSERT (iiDiffSecs == 3600) would expect; // but I get 7200, which is 2 hours !
So what am I missing here?
SystemTimeToFileTime () as UTC time (which has no concept of DST) Means its first argument, so your
ft1_local and
ft2_local objects are always going to be two hours apart as you change the data format, but not in real time.
Sthaniyfailtaimtofhailtaim () then you will apply the same offset to have it, so
ft1_utc and
ft2_utc will always be two hours apart. < P> As a document, "Time zone and daylight saving time" (emphasis Muay) of "Sthaniyfailtamtofhailtaim behind current settings Uses" current time when you have four hours UTC, for example, whenever you will only deduct four hours pass it, then , Even though at that time it was originally represented some time on the other side of DST.
EDIT: Against the comments, here's how the second difference between the two local time in standard C is found:
#include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Time.h> Int main (zero) {struct tm start_time; Start_time.tm_year = 115; Start_time.tm_mon = 2; Start_time.tm_mday = 8; Start_time.tm_hour = 1; Start_time.tm_min = 30; Start_time.tm_sec = 0; Start_time.tm_isdst = -1; Structure TM & amp; nbsp; time; End_time.tm_year = 115; End_time.tm_mon = 2; End_time.tm_mday = 8; End_time.tm_hour = 3; End_time.tm_min = 30; End_time.tm_sec = 0; End_time.tm_isdst = -1; Time_t start_tm = mk time (& amp; start_time); Time_t and_tm = mk time (and end_time); If (start_tm == -1 || and_tm == -1) {fputs ("Could not get local time.", Stderr); Exhaust (EXIT_FAILURE); } Double second_ff = defame (end_tm, RTITM); Printf ("% .1f second is the difference. \ N", second_df); Return EXIT_SUCCESS; }
which outputs:
paul @ thoth: ~ / src $ ./difftime 3600.0 seconds is the difference. Paul @ thoth: ~ / src $
As you are expecting.
Note that,
struct tm :
tm_year expressed in year 1900 , So that we can achieve 2015
tm_mon is in category 0, although 11, then 2 is March, not 3.
There are other times as you expect
When
tm_isdst is passed to
-1 is set to ,
mktime () is in DST or will not attempt to know for yourself the impact on the local time we supplied, which We want to do it here, here.
Comments
Post a Comment