#include #include "FluxTime.h" #include "ui.h" #include "esp_err.h" #include "esp_log.h" /*包含SNTP的头文件*/ #include "lwip/apps/sntp.h" #include void time_synic_task(void *arg) { /*用来进行显示的字符串*/ char strftime_buf[64]; /*大数*/ time_t now = 0; /*时间结构体*/ struct tm timeinfo = {0}; ESP_LOGI("SNTP..........","SNTP task start"); while (1) { /*1秒钟更新一下显示时间*/ vTaskDelay(1000 / portTICK_PERIOD_MS); time(&now); localtime_r(&now, &timeinfo); strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); lv_label_set_text_fmt(ui_pageTimeDebug_labelHearderTime,"%s",strftime_buf); ESP_LOGI("SNTP","The current date/time in China is: %s", strftime_buf); } } char get_time_str(void) { char strftime_buf[64]; time_t now = 0; struct tm timeinfo = {0}; time(&now); localtime_r(&now, &timeinfo); strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); return strftime_buf; }