c++ clock_gettime() and daylight savings

前端 未结 4 1649
终归单人心
终归单人心 2021-01-23 02:07

I am using clock_gettime() in my C++ program to get the current time. However, the return value is seconds since epoch in UTC. This code can get messed up in my time zone durin

4条回答
  •  感情败类
    2021-01-23 02:31

    If you are using Windows, you can use this GetTimeZoneInformation, but you have to include the Windows API.

    Another methode to achieve this would be the struct tm. You will find the details here: struct tm. "The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available." I think this is the easier way.

提交回复
热议问题