I am trying to obtain the timestamp to the degree of microseconds in my program:
time_t t = time(NULL);
struct tm tm = *localtime(&t);
Buffer[Size-1] = 0;
char* BufferAsString = (char*)(Buffer+header_size);
if (strstr(BufferAsString,"Laptop Timestamp")){
fprintf(timestampFile, "now: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
fprintf(timestampFile,BufferAsString);
fprintf(timestampFile,"\n");
fflush(timestampFile);
}
Currently this produces:
now: 2021-09-19 10:46:07
But I would like it to be
now: 2021-09-19 10:46:06.98164
I don't think tm is accurate to this degree according to this: https://www.cplusplus.com/reference/ctime/tm/
Is there another method of going about this?
I am using a raspberry pi 4 running the latest version of raspbian.