Problem with mktime() and difftime()
Posted: Sat Apr 30, 2022 5:31 pm
Hi, I had a problem with mktime() and difftime(). I need to calculate time interval between now and a specific time. I used LOGI to log my local_time and alarm_time, when I calculate time interval between someday in the same month, it works fine. But when I use difftime() to calculate time interval between 23:59:00 04/30/2022 and 07:00:00 05/01/2022, it likely add 86400 ( = 24*60*60 secs) to result. I tested for other month and it did too.
Please help me solve this problem.
Sorry for my English
Please help me solve this problem.
Sorry for my English
- time_t i2clocaltime = mktime(&local_time);
- time_t alrmtime = mktime(&alarm_time);
- double remain_time = difftime(alrmtime,i2clocaltime);
- ESP_LOGI(TAG,"Alarm time %04d-%02d-%02d %02d:%02d:%02d",alarm_time.tm_year,alarm_time.tm_mon,alarm_time.tm_mday,alarm_time.tm_hour,alarm_time.tm_min,alarm_time.tm_sec);
- ESP_LOGI("Remain time","time %f",remain_time);
- I (10623) MQTT_DAQ: today 2022-04-30 23:59:13
- I (10623) MQTT_DAQ: Alarm time 2022-05-01 07:00:00
- I (10633) Remain time: time 111647.000000
- I (10643) MQTT_DAQ: File written
- I (150633) MQTT_DAQ: File written