How can a Windows program temporarily change its time zone?

后端 未结 8 1817
清酒与你
清酒与你 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:23

    Please don't call SetTimeZoneInformation - there is no thread or process-specific notion of a time zone in Windows. As others say, the easiest way is to mock out the timezone code - with Pex/Mocks, you can mock out even static methods, which means you can hook the standard .NET Timezone code to replace it with your own. If you're using C/C++, you just need to wire up the code to have the TZ info be mockable.

提交回复
热议问题