title: time(NULL) returning different time
body: <p>I am trying to get current time in C using <code>time_t current_time = time(NULL)</code>.
  As I understand, it would return me the current time of system.
  I am later trying to convert it into GMT time using struct <code>tm* gmt = gmtime(&amp;current_time)</code>.</p>
  
  <p>I print both times using <code>ctime()</code> and <code>asctime()</code> functions.</p>
  
  <p>The current time on my system is GMT + 1. But <code>gmtime()</code> returns me the same time as <code>current_time</code> is. I could not understand why <code>gmtime()</code> is returning me same time. Any help will be appreciated.</p>
  
  <p>Ok here is the code and the output: Current time that windows is showing is 17:54 (Stockholm zone; GMT+1). I want something to return me 15:54. Or perhaps my understanding is wrong ...</p>
  
  <pre><code>time_t current_time = time(NULL);
  
  struct tm* gmt = gmtime(&amp;current_time);
  struct tm* loc = localtime(&amp;current_time);
  
  printf("current time: %s\n", ctime(&amp;current_time));
  printf("gmt time %s\n", asctime(gmt));
  printf("local time %s\n", asctime(loc));
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>current time: Mon Oct  8 17:54:06 2012
  
  gmt time Mon Oct  8 17:54:06 2012
  
  local time Mon Oct  8 17:54:06 2012
  </code></pre>
  
  <p><strong>Accepted Solution:</strong> <strong>From Simes</strong></p>
  
  <p>That's probably your problem. Check the value of your TZ environment variable; if not present, it will default to GMT. Cygwin doesn't automatically pick up the time zone setting from Windows. See also <a href="https://stackoverflow.com/questions/11655003/localtime-returns-gmt-for-windows-programs-running-on-cygwin-shells">localtime returns GMT for windows programs running on cygwin shells</a></p>