user82982: If I call configTime() on a ESP8266 using ESP8266 Core, then time() gets changed from uptime to unixtime. However this sends a SNTP request. I have a DS3231 RTC attached without internet. How can I set time() without calling configTime()?
Thanks in advance

user70436: Whenever you have epoch time, either from RTC, NTP, etc., use the POSIX function settimeofday() to set system time as @Majenko said
The sample code is as follows:
// Assuming we already have Unix `epoch` time, which is time from Jan 1 1970.
// From RTC, NTP, etc.
time_t epoch_t = epoch;

// set the time to UTC
setTime(epoch_t);

// set the system time to UTC
timeval tv = { epoch_t, 0 };
settimeofday(&tv, nullptr);

// Now we can have system time by calling time()
time_t timeNowUTC;
struct tm * timeInfo

timeNowUTC = time(nullptr);
timeInfo = localtime(&timeNowUTC);


For the record, the issue has been solved in Arduino Forum : Update time() from DS3231

82982: <p>If I call configTime() on a ESP8266 using ESP8266 Core, then time() gets changed from uptime to unixtime. However this sends a SNTP request. I have a DS3231 RTC attached without internet. How can I set time() without calling configTime()?</p>
<p>Thanks in advance</p>
 70436: <p>Whenever you have <code>epoch</code> time, either from RTC, NTP, etc., use the POSIX function settimeofday() to set system time as @Majenko said</p>
<p>The sample code is as follows:</p>
<pre><code>// Assuming we already have Unix `epoch` time, which is time from Jan 1 1970.
// From RTC, NTP, etc.
time_t epoch_t = epoch;

// set the time to UTC
setTime(epoch_t);

// set the system time to UTC
timeval tv = { epoch_t, 0 };
settimeofday(&amp;tv, nullptr);

// Now we can have system time by calling time()
time_t timeNowUTC;
struct tm * timeInfo

timeNowUTC = time(nullptr);
timeInfo = localtime(&amp;timeNowUTC);
</code></pre>
<hr />
<p>For the record, the issue has been solved in Arduino Forum : <a href="https://forum.arduino.cc/t/update-time-from-ds3231/962252/5" rel="nofollow noreferrer"><strong>Update time() from DS3231</strong></a></p>
