34 ESP_LOGVV(TAG,
"Got epoch %" PRIu32, epoch);
39 ts.tv_sec =
static_cast<time_t
>(epoch);
41 int ret = clock_settime(CLOCK_REALTIME, &ts);
44 ESP_LOGW(TAG,
"clock_settime() failed with code %d", ret);
47 struct timeval timev {
48 .tv_sec =
static_cast<time_t
>(epoch), .tv_usec = 0,
50 struct timezone tz = {0, 0};
51 int ret = settimeofday(&timev, &tz);
55 ret = settimeofday(&timev,
nullptr);
58#ifdef USE_TIME_TIMEZONE
64 ESP_LOGW(TAG,
"setimeofday() failed with code %d", ret);
67 auto time = this->
now();
68 ESP_LOGD(TAG,
"Synchronized time: %04d-%02d-%02d %02d:%02d:%02d", time.year, time.month, time.day_of_month, time.hour,
69 time.minute, time.second);