My time zone is set to CDT in the control panel Date/Time applet.
The following code places exactly the same date and time into pCurGmtTime and pCurTime:
int main(int argc, char *argv[])
{
__time32_t t=_time32(NULL);
tm *pCurGmtTime=_gmtime32(&t);
tm *pCurTime=_localtime32(&t);
// The values in the *pCurGmtTime structure are equal to the values in *pCurTime
return 0;
}
I don’t have the TZ environment variable set, but my time zone is properly configured for the system via the Control Panel Date and Time applet. This behavior seems to go against the MSDN documentation for these functions, which says that TZ overrides the control panel settings, but if it is absent the control panel settings will be used.
Thanks
Because
The second call writes data to the same location as the previous one. You need to copy the data somewhere else before calling
localtime.