33 ESP_LOGVV(TAG,
"Got epoch %" PRIu32, epoch);
38 ts.tv_sec =
static_cast<time_t
>(epoch);
40 int ret = clock_settime(CLOCK_REALTIME, &ts);
43 ESP_LOGW(TAG,
"clock_settime() failed with code %d", ret);
46 struct timeval timev {
47 .tv_sec =
static_cast<time_t
>(epoch), .tv_usec = 0,
49 struct timezone tz = {0, 0};
50 int ret = settimeofday(&timev, &tz);
54 ret = settimeofday(&timev,
nullptr);
57#ifdef USE_TIME_TIMEZONE
63 ESP_LOGW(TAG,
"setimeofday() failed with code %d", ret);
66 auto time = this->
now();
67 ESP_LOGD(TAG,
"Synchronized time: %04d-%02d-%02d %02d:%02d:%02d", time.year, time.month, time.day_of_month, time.hour,
68 time.minute, time.second);