KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 that's not my local time), get the corresponding time value in GMT. I.e., something along the lines of time_t get_gmt_time(time_t local_time, const char* time_zone); As deceptively simple as it sounds, the closest I could find was the following code snippet from timegm's man page: #include <time.h> #include <stdlib.h> time_t my_timegm(struct tm *tm) { time_t ret; char *tz; tz = getenv("TZ"); setenv("TZ", "", 1); tzset(); ret = mktime(tm); if (tz) setenv("TZ", tz, 1); else unsetenv("TZ"); tzset(); return ret; } There gotta be a better way than this belligerently not thread-safe abomination, right? Right??
Tags (comma-separated)
Save Edits
Cancel