M. The answer of MARIE does not actually work for the question posed: tzset () is POSIX, but not ANSI C, as the name of the original question. This is not mentioned either on the C90 or on the C99 (from the search for draft standards, I do not have access to the final standards).
The OP question is perhaps a bit vague, as it is not clear what it means by “utc time”, but presumably it means broken components, say filled in struct tm .
In C99, you can determine the local TZ offset from UTC by parsing strftime("%z",...) output strftime("%z",...) (make sure you call it with your own date values, as this offset will change over time); but this format code is not available on the C90, so AFAIK is out of luck if you have to match the C90, if you do not try to parse the output of strftime("%z",...) , but it will be fundamentally not portable.
You can then convert your UTC components to time_t using mktime() , although they will be interpreted as in the local time zone; then apply the offset and convert back to broken components using localtime() . You may encounter extreme cases at a time when your local time zone switches to and from DST (or when you change your clockwise shift when this is done), but this can easily be avoided by going to a locale that does not use DST. or improved set tm_dst to 0 when calling both strftime() and mktime() .
Alternatively, do not limit yourself to ANSI C.
source share