Time zone conversion C API on Linux, anyone?

后端 未结 6 1195
终归单人心
终归单人心 2020-12-29 03:40

I\'m looking for something that I presumed would be very simple - given local Unix time in a specific time zone (specified as a string, e.g., \"America/New_York\" - note tha

6条回答
  •  囚心锁ツ
    2020-12-29 03:58

    Why can't you use the gmtime_r()? Following worked fine for me:

    int main()
    {
        time_t t_gmt, t_local=time(NULL);
        struct tm tm_gmt;
    
        gmtime_r(&t_local, &tm_gmt);
    
        t_gmt = mktime(&tm_gmt);
    
        printf("Time now is:    %s", ctime(&t_local));
        printf("Time in GMT is: %s", ctime(&t_gmt));
    
        return 0;
    }
    

提交回复
热议问题