Created
August 26, 2011 09:15
-
-
Save bonifaido/1173030 to your computer and use it in GitHub Desktop.
This small program prints a timestamp with milliseconds included
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <sys/time.h> | |
void printTime() | |
{ | |
char buffer[32]; | |
struct timeval timevalue; | |
struct tm *timeinfo; | |
gettimeofday(&timevalue, NULL); | |
timeinfo = localtime(&timevalue.tv_sec); | |
strftime(buffer, 32, "%Y.%m.%d-%H.%M.%S.%03d", timeinfo); | |
// adding milliseconds to it | |
sprintf(buffer, buffer, timevalue.tv_usec / 1000); | |
puts(buffer); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
printTime(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment