Get the time zone GMT offset in C
问题 I'm using the standard mktime function to turn a struct tm into an epoch time value. The tm fields are populated locally, and I need to get the epoch time as GMT. tm has a gmtoff field to allow you to set the local GMT offset in seconds for just this purpose. But I can't figure out how to get that information. Surely there must be a standard function somewhere that will return the offset? How does localtime do it? 回答1: Just do the following: #define _GNU_SOURCE /* for tm_gmtoff and tm_zone */