Skip to content

setTime from tm #8

@jcherrabi

Description

@jcherrabi

hello i added a function to set the time from a time struct tm which is usefull when you get time from an NPT server.

add this to ESP32Time.cpp
void ESP32Time::setTimeStruct(tm t) { time_t timeSinceEpoch = mktime(&t); setTime(timeSinceEpoch, 0); }
and ESPTime.h
void setTimeStruct(tm t);
usage:
/* ----------------------------Initialize and get NPT Time-------------------------- */ configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); struct tm timeinfo; if (getLocalTime(&timeinfo)) { rtc.setTimeStruct(timeinfo); }

Hope this helps!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions