Possible Duplicate:
How do I get milliseconds since midnight UTC in C?
I'm trying to get the time elapsed in milliseconds between the start of the current day (12:00:00.0000 AM) to the current time. What would I use in time.h to achieve this?
Possible Duplicate:
How do I get milliseconds since midnight UTC in C?
I'm trying to get the time elapsed in milliseconds between the start of the current day (12:00:00.0000 AM) to the current time. What would I use in time.h to achieve this?
If you mean the time of day since epoch:
struct timeval time;
gettimeofday(&time, NULL);
If you mean the system time:
time_t t;
time(&t);
While I realize you asked for milliseconds, this is how you can get that in seconds:
time(NULL)%(24*60*60)
How do I get milliseconds since midnight UTC in C?
This is a simple way:
time_t seconds_since_midnight = time(NULL) % 86400;
To get approximate milliseconds since midnight, multiply
seconds_since_midnight
by 1000.If you need more resolution (consider whether you really do), you will have to use another function such as
gettimeofday()
.