Get the current time, in milliseconds, in C?
c
Solution
#include <sys/time.h>
/**
* @brief provide same output with the native function in java called
* currentTimeMillis().
*/
int64_t currentTimeMillis() {
struct timeval time;
gettimeofday(&time, NULL);
int64_t s1 = (int64_t)(time.tv_sec) * 1000;
int64_t s2 = (time.tv_usec / 1000);
return s1 + s2;
}
I write this function just like `System.currentTimeMillis()` in Java, and they have the same output.
Problem
What is the equivalence of the Java's `System.currentTimeMillis()` in C?