C language Get the current time in milliseconds

https‮.www//:‬lautturi.com
C language Get the current time in milliseconds

Get the current time in milliseconds

/*
Example: get current time in milliseconds in C language
*/

#include <stdio.h>
#include <stdlib.h>

#include <sys/time.h>

int main(void) {

    struct timeval te;
    // Get the current time  
    gettimeofday(&te, NULL);
    // convert into milliseconds
    long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000;
    printf("milliseconds: %lld\n", milliseconds);

    return 0;
}
Created Time:2017-08-28 19:24:10  Author:lautturi