using gettimeofday() equivalents on windows
<p>I'm trying to use 2 different equivalents for UNIX's gettimeofday() function on Windows, using Visual Studio 2013.</p>

<p>I took the first one from <a href="https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows">here</a>. As the second one, I'm using the _ftime64_s function, as explained <a href="https://msdn.microsoft.com/en-us/library/95e68951(v=vs.80).aspx" rel="nofollow noreferrer">here</a>.</p>

<p>They work, but not as I expected. I want to get different values when printing the seconds, or at least the milliseconds, but I get the same value for the printings with gettimeofday() (mytime1 &amp; mytime2) and with _ftime64_s (mytime3 &amp; mytime4). </p>

<p>However, it worth mentioning that the value of the milliseconds is indeed different between these two functions (that is, the milliseconds value of mytime1/mytime2 is different from mytime3/mytime4).</p>

<p>Here's my code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;Windows.h&gt;
#include &lt;stdint.h&gt;
#include &lt;sys/timeb.h&gt;
#include &lt;time.h&gt;

#define WIN32_LEAN_AND_MEAN

int gettimeofday(struct timeval * tp, struct timezone * tzp)
{
    // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
    static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);

    SYSTEMTIME  system_time;
    FILETIME    file_time;
    uint64_t    time;

    GetSystemTime(&amp;system_time);
    SystemTimeToFileTime(&amp;system_time, &amp;file_time);
    time = ((uint64_t)file_time.dwLowDateTime);
    time += ((uint64_t)file_time.dwHighDateTime) &lt;&lt; 32;

    tp-&gt;tv_sec = (long)((time - EPOCH) / 10000000L);
    tp-&gt;tv_usec = (long)(system_time.wMilliseconds * 1000);
    return 0;
}

int main()
{
    /* working with struct timeval and gettimeofday equivalent */

    struct timeval mytime1;
    struct timeval mytime2;

    gettimeofday(&amp;(mytime1), NULL);
    gettimeofday(&amp;(mytime2), NULL);

    printf("Seconds: %d\n", (int)(mytime1.tv_sec));
    printf("Milliseconds: %d\n", (int)(mytime1.tv_usec));

    printf("Seconds: %d\n", (int)(mytime2.tv_sec));
    printf("Milliseconds: %d\n", (int)(mytime2.tv_usec));

    /* working with _ftime64_s */

    struct _timeb mytime3;
    struct _timeb mytime4;

    _ftime64_s(&amp;mytime3);
    _ftime64_s(&amp;mytime4);

    printf("Seconds: %d\n", mytime3.time);
    printf("Milliseconds: %d\n", mytime3.millitm);

    printf("Seconds: %d\n", mytime4.time);
    printf("Milliseconds: %d\n", mytime4.millitm);

    return (0);
}
</code></pre>

<p>I tried other format specifiers (%f, %lu) and castings ((float), (double), (long), (size_t)), but it didn't matter. Suggestions will be welcomed.</p>