mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
print timestamp with milliseconds precision
This commit is contained in:
parent
625f6781af
commit
d50b200ae6
1 changed files with 5 additions and 4 deletions
|
|
@ -23,24 +23,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "tio/error.h"
|
||||
#include "tio/print.h"
|
||||
|
||||
char * current_time(void)
|
||||
{
|
||||
static char time_string[20];
|
||||
time_t t;
|
||||
struct tm *tmp;
|
||||
struct timeval tv;
|
||||
|
||||
t = time(NULL);
|
||||
tmp = localtime(&t);
|
||||
gettimeofday(&tv, NULL);
|
||||
tmp = localtime(&tv.tv_sec);
|
||||
if (tmp == NULL)
|
||||
{
|
||||
error_printf("Retrieving local time failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
strftime(time_string, sizeof(time_string), "%H:%M:%S", tmp);
|
||||
sprintf(time_string, "%2d:%02d:%02d.%03d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tv.tv_usec/1000);
|
||||
|
||||
return time_string;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue