You should use the strptime() for this purpose. It converts a string representation of time to a time tm structure. strptime() works as the oppsite of strftime() function. Now let's see how the date obtained from the esp_app_desc_t can be converted to unix time as time_t.
Merge the date and time fields of esp_app_desc_t into a buffer:
char buf[32];
const esp_app_desc_t *app_desc = esp_app_get_description();
// Merge date and time fields
strncpy(buf, app_desc->date, sizeof(buf));
strncat(buf, " ", sizeof(buf) - strlen(buf) - 1);
strncat(buf, app_desc->time, sizeof(buf) - strlen(buf) - 1);
Then convert it to time_t
time_t prod_time;
struct tm prod_tm;
memset(&prod_tm, 0, sizeof(prod_tm));
strptime(buf, "%b %d %Y %H:%M:%S", &prod_tm);
prod_time = mktime(&prod_tm);
Here is the full snippet:
#include <time.h>
#include <string.h>
#include "esp_log.h"
void production_time_to_ctime(void)
{
char buf[32];
time_t prod_time;
const esp_app_desc_t *app_desc = esp_app_get_description();
// Merge date and time fields
strncpy(buf, app_desc->date, sizeof(buf));
strncat(buf, " ", sizeof(buf) - strlen(buf) - 1);
strncat(buf, app_desc->time, sizeof(buf) - strlen(buf) - 1);
ESP_LOGI(TAG, "production_time_init: merged time string: %s", buf);
struct tm prod_tm;
memset(&prod_tm, 0, sizeof(prod_tm));
strptime(buf, "%b %d %Y %H:%M:%S", &prod_tm);
prod_time = mktime(&prod_tm);
ESP_LOGI(TAG, "production_time_init: unix time: %lld", prod_time);
}
References