Skip to content

Instantly share code, notes, and snippets.

@bonifaido
Created August 26, 2011 09:15
Show Gist options
  • Save bonifaido/1173030 to your computer and use it in GitHub Desktop.
Save bonifaido/1173030 to your computer and use it in GitHub Desktop.
This small program prints a timestamp with milliseconds included
#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