title: How do I get time_t in GMT on Windows in C
body: <p>I am writing some code that will run on multiple intercommunicating systems. I was using time() to get time_t, but this was causing problems with time zone differences between the systems, so I want to get time_t in GMT. I've been looking through the time.h functions, but it is unclear to me how I can be sure that I will get the time correctly. This is what I've come up with so far:</p>
  
  <pre><code>time_t t = time();
  struct tm *gtm = gmtime(&amp;t);
  time_t gt = mktime(gtm);
  </code></pre>
  
  <p>Now, this seems to get the correct answer on my machine, but I want to know if it will work universally before I push it out, even if the other machines' clocks are set to local time or GMT or in different time zones or whatever. The reason I am concerned is because of mktime. In the description, it says that it interprets the tm struct as "a calendar time expressed in local time." That sounds to me like it will not be returning the GMT time, though it seems to be on my machine. Also, when I print out gt, it is 4 hours ahead of t, which seems right. But if I run the following:</p>
  
  <pre><code>time_t t = time();
  struct tm *gtm = gmtime(&amp;t);
  struct tm *ltm = localtime(&amp;t);
  printf("%d, %d\n", gtm-&gt;tm_hour, ltm-&gt;tm_hour);
  </code></pre>
  
  <p>the hours are the same and are local time, which is not what I expected.</p>
  
  <p>For the record, in another answer, I saw reference to timegm(), which sounds perfect, but it does not exist on my system.</p>
  
  <p>So in short, how do I get time_t in GMT on any Windows machine in C?</p>
  
  <p>Edit: removed msvcrt tag that was added, as I am not using the msvcrt.</p>