I would like to create a function that will fill a struct with the current date and time, such as:
typedef struct DateAndTime
{
int year;
int month;
int day;
int hour;
int minutes;
int seconds;
int msec;
}DateAndTime;
I know I can use localtime()
from time.h
, but the problem is that it gives me only time in seconds, and I want to get it also in milliseconds resolution. I know I might be able to use also gettimeofday()
for this, but how can i combine those to get the above struct filled? Or maybe other function that gives milliseconds resolution?
How can i achieve this?
Note: My system is linux based.