【已解决】IDF4.4 的SNTP接口是否有获取毫秒级别时间的方法
Posted: Fri Apr 21, 2023 9:32 am
基于例程中SNTP接口实现获取网络时间戳后,发现精度只能到秒级,SNTP是否有获取毫秒级时间的办法呢?
// update 'now' variable with current time
time(&now);
// Set timezone to China Standard Time
setenv("TZ", "CST-8", 1);
tzset();
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
ESP_LOGI(TAG, "The current date/time in Shanghai is: %s", strftime_buf);
ESP_LOGI(TAG, "timestamp = %ld", now);
// update 'now' variable with current time
time(&now);
// Set timezone to China Standard Time
setenv("TZ", "CST-8", 1);
tzset();
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
ESP_LOGI(TAG, "The current date/time in Shanghai is: %s", strftime_buf);
ESP_LOGI(TAG, "timestamp = %ld", now);