Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the problem is here:</p> <p><a href="http://pubs.opengroup.org/onlinepubs/009604599/functions/mktime.html" rel="nofollow"><code>The mktime() function shall convert the broken-down time, expressed as local time, in the structure pointed to by timeptr, into a time since the Epoch value...</code></a></p> <p>Note the words <code>local time</code>. The C standard has them too in the description of <code>mktime()</code>:</p> <p><code>The mktime function converts the broken-down time, expressed as local time, in the structure pointed to by timeptr into a calendar time value with the same encoding as that of the values returned by the time function.</code></p> <p><code>gmtime()</code>, on the other hand, produces time in GMT/UTC and not in your time zone:</p> <p><a href="http://pubs.opengroup.org/onlinepubs/009604599/functions/gmtime.html" rel="nofollow"><code>The gmtime() function shall convert the time in seconds since the Epoch pointed to by timer into a broken-down time, expressed as Coordinated Universal Time (UTC).</code></a></p> <p><strong>EDIT</strong>: If you just want 19:00 of the previous GMT/UTC day, you can do this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;time.h&gt; int main(void) { time_t currentTime; struct tm *brokenDownTime; time(&amp;currentTime); // get the time in GMT as we are in PDT brokenDownTime = gmtime(&amp;currentTime); printf("Current Time (GMT): %2d:%02d\n" " seconds since Epoch: %ld\n", brokenDownTime-&gt;tm_hour, brokenDownTime-&gt;tm_min, (long)currentTime); // "Unwind" time to 0:00:00 (assuming time_t is an integer): currentTime /= 24 * (time_t)3600; currentTime *= 24 * (time_t)3600; brokenDownTime = gmtime(&amp;currentTime); printf("Time at the beginning of the current GMT day: %2d:%02d\n" " seconds since Epoch: %ld\n", brokenDownTime-&gt;tm_hour, brokenDownTime-&gt;tm_min, (long)currentTime); // Add 19 hours: currentTime += 19 * (time_t)3600; brokenDownTime = gmtime(&amp;currentTime); printf("Time at 19:00:00 of the current GMT day: %2d:%02d\n" " seconds since Epoch: %ld\n", brokenDownTime-&gt;tm_hour, brokenDownTime-&gt;tm_min, (long)currentTime); // Subtract 1 day: currentTime -= 24 * (time_t)3600; brokenDownTime = gmtime(&amp;currentTime); printf("Time at 19:00:00 of the previous GMT day: %2d:%02d\n" " seconds since Epoch: %ld\n", brokenDownTime-&gt;tm_hour, brokenDownTime-&gt;tm_min, (long)currentTime); return 0; } </code></pre> <p>Output:</p> <pre><code>Current Time (GMT): 13:23 seconds since Epoch: 1341235429 Time at the beginning of the current GMT day: 0:00 seconds since Epoch: 1341187200 Time at 19:00:00 of the current GMT day: 19:00 seconds since Epoch: 1341255600 Time at 19:00:00 of the previous GMT day: 19:00 seconds since Epoch: 1341169200 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload