Convert time_t from localtime zone to UTC

前端 未结 3 1725
眼角桃花
眼角桃花 2021-01-02 03:57

I have a time_t that represents the time in seconds since epoch. Those seconds refer to the local time.

I want to convert them to UTC.

Is there

3条回答
  •  孤独总比滥情好
    2021-01-02 04:10

    You can use gmtime:

    Convert time_t to tm as UTC time Uses the value pointed by timer to fill a tm structure with the values that represent the corresponding time, expressed as a UTC time (i.e., the time at the GMT timezone).

    (c) http://www.cplusplus.com/reference/ctime/gmtime/

提交回复
热议问题