Languages

Menu
Sites
Language
Convert sensors timestamp in current date

Hi everybody,
i'm trying to develop an app that collects milliseconds hear rate data and write them into a txt file. I need also to stamp on the txt the right time and date to know when the event has happened.
is there way convert the timestamp of the sensor into a format Hours:Minutes:seconds??



typedef struct
{
int accuracy; /**< Accuracy of sensor data */
unsigned long long timestamp; /**< Time when the sensor data was observed */
int value_count; /**< Number of sensor data values stored in #sensor_event_s::values */
float values[MAX_VALUE_SIZE]; /**< Sensor data values */
} sensor_event_s;

this is an example of how the .txt file comes up:

556 , 430919201689
556 , 430919254262
556 , 430919302796
556 , 430919356167
556 , 430919402654
556 , 430919454530
556 , 430919502442
556 , 430919554832
556 , 430919603255
907 , 430919655868
907 , 430919702992
907 , 430919754935
907 , 430919802831

The first column contains the milliseconds, while the second one contains the timestamp.
Thank you,

Responses

2 Replies
Joshua McAdams

If the timestamp is epoch time (which it seems like it should be, but I can't find anything in the documentation saying it is), you can use the functions included in the time.h header.

https://linux.die.net/man/3/localtime

Describes each function, the time_t argument for each function should be the timestamp value in the structure sensor_event_s. You could use the ctime function to write the string, or store it into a struct tm with localtime and make your own string.

Joshua McAdams

Can't edit, but looks like I was incorrect on the timestamp value. Maybe someone else can chime in on it's value. It's not relaly clearly defined anywhere.