How can a Windows program temporarily change its time zone?

后端 未结 8 1822
清酒与你
清酒与你 2021-02-05 20:45

I\'ve written a function to return the time_t value corresponding to midnight on a given day. When there is no midnight for a given day, it returns the earliest tim

8条回答
  •  日久生厌
    2021-02-05 21:22

    Check out _putenv_s and _tzset. In theory, you should be able to set the TZ environment variable for your process with _putenv_s and then use _tzset to set the actual local time zone for your process to what the TZ environment variable is set to.

    I know that this works on Linux with putenv and tzset, and from the documentation of _putenv_s and _tzset, it appears that you should be able to do the same with them on Windows. I haven't actually tried it though.

提交回复
热议问题