Programming Tips - How can I get the current time in milliseconds?

Date: 2015sep4 OS: Linux Language: C/C++ Q. How can I get the current time in milliseconds? A. Use gettimeofday() like this:
#include <sys/time.h> long currentMillis() { struct timeval tp; gettimeofday(&tp, NULL); return tp.tv_sec * 1000 + tp.tv_usec / 1000; // Convert the seconds to milliseconds by multiplying by 1000 // Convert the microseconds to milliseconds by dividing by 1000 }
By the way:
#include <time.h> time_t now = time(NULL);
Gives you the current time in seconds.