Hi all,
I would like to ask if there is anyway to convert String to datetime format as i have to add 2 hours to the datetime log should the particle could not connect to the particle cloud. The output of my String is Tue Jun 13 07:08:11 2017 as read from my sd logger.
Thanks!
What about something like this
struct tm tm;
time_t epoch;
if ( strptime(timestamp, "%Y-%m-%d %H:%M:%S", &tm) != NULL )
epoch = mktime(&tm);
else
Then add your time shift in seconds to the unix time and convert it back again. This is how I do daylight savings shifts, then you don’t need to worry about date rollver or anything.
Regards
Marshall
@marshall, I can’t convert the string into the data type required. I have converted the output to 2017-6-13 9:54:13 this format but the mktime function does not work. Do i have to parse individual characters to process the calculation? Or do i have to convert the String to Unix time to process the input into mktime?
Hi @marshall, I managed to make it work!! Thanks for for the tip!!
1 Like