c++ clock_gettime() and daylight savings

前端 未结 4 1729
终归单人心
终归单人心 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:30

    #include 
    time_t rawtime;
    struct tm *timeinfo;
    
        time(&rawtime);
        timeinfo = localtime(&rawtime);
        if (timeinfo->tm_isdst)
            Hour -= 1; // daylight savings time
    

提交回复
热议问题