How can a Windows program temporarily change its time zone?

后端 未结 8 1792
清酒与你
清酒与你 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.

    0 讨论(0)
  • 2021-02-05 21:29

    With VS 2008 (C++ native) I was able to modify the behavior of localtime() by changing the _timezone variable.

    I agree, this is not a clean way to do, but at least this could be a workaround.

    Of course, you need to do the math by yourself to find the number of seconds between UTC and your 'new' timezone.

    0 讨论(0)
提交回复
热议问题