title: How to convert a UTC date & time to a time_t in C++?
body: <p>I want to convert a UTC date &amp; time given in numbers for year, month, day, etc. to a time_t. Some systems offer functions like <code>mkgmtime</code> or <code>timegm</code> for this purpose but that is not standard and does not exist on my Solaris system.</p>
  
  <p>The only solution I have found so far involves setting the local time zone to UTC with setenv and then call <code>mktime</code>. However this approach is not thread-safe, slow, not portable and even generates a memory leak on my system.</p>
  
  <p>I have also seen approaches that tried to determine the current UTC offset using <code>gmtime</code> and then adding that to the result of <code>mktime</code>. But as far as I have seen all those approaches had gaps. After all, the conversion from the local time to UTC is not unique.</p>
  
  <p>What do you think is the best solution?</p>