====== IrtcSet() ====== ''IrtcSet()'' sets the RTC date and time. {{:en-us_commands:reference:irtcset.svg?900|IrtcSet command operation flow}} ''bool IrtcSet(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)''\\ ''bool IrtcSet(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second)'' ===== Commands ===== ^ Command ^ Arguments ^ Return Value ^ Operation ^ | ''IrtcSet(year, month, day, hour, minute, second)'' | ''uint16_t year'' — ''2000~2099''\\ ''uint8_t month'' — ''1~12''\\ ''uint8_t day'' — Valid day of the specified month\\ ''uint8_t hour'' — ''0~23''\\ ''uint8_t minute'' — ''0~59''\\ ''uint8_t second'' — ''0~59'' | ''bool'' | Sets the RTC date and time. | ===== Example ===== void setup() { Serial.begin(115200); if (!IrtcBegin()) return; // Check the DS3231 RTC connection and begin operation. bool valid = false; if (IrtcTimeValid(valid) && !valid) { // Check whether the RTC time is reliable. IrtcSet(2026, 9, 7, 9, 0, 0); // Set the RTC date and time. IrtcClearOscillatorStopFlag(); // Clear the oscillator-stop flag. } } void loop() { IrtcDateTime now; uint32_t unixTime = 0; float rtcTemperature = 0.0F; if (IrtcRead(now) && IrtcUnixTime(unixTime) && IrtcGetTemperature(rtcTemperature)) { // Return the RTC's internal temperature. / Return the current time as Unix time. / Read the RTC date and time. Serial.print(unixTime); Serial.print(','); Serial.println(rtcTemperature, 2); } delay(1000); } ===== Precautions ===== Run each device's corresponding ''Begin'' command first. Check I²C addresses and pin sharing; if the ''bool'' return value is ''false'', inspect wiring and power. ===== Built-in Commands in the Same Category ===== * [[:en-us_commands:reference:irtcbegin|IrtcBegin() View detailed description]] * [[:en-us_commands:reference:irtcread|IrtcRead() View detailed description]] * [[:en-us_commands:reference:irtcunixtime|IrtcUnixTime() View detailed description]] * [[:en-us_commands:reference:irtcgettemperature|IrtcGetTemperature() View detailed description]] * [[:en-us_commands:reference:irtctimevalid|IrtcTimeValid() View detailed description]] * [[:en-us_commands:reference:irtcclearoscillatorstopflag|IrtcClearOscillatorStopFlag() View detailed description]] * [[:en-us_commands:reference:irtcsetalarm1|IrtcSetAlarm1() View detailed description]] * [[:en-us_commands:reference:irtcsetalarm2|IrtcSetAlarm2() View detailed description]] * [[:en-us_commands:reference:irtcalarmenable|IrtcAlarmEnable() View detailed description]] * [[:en-us_commands:reference:irtcalarmenabled|IrtcAlarmEnabled() View detailed description]] * [[:en-us_commands:reference:irtcalarmtriggered|IrtcAlarmTriggered() View detailed description]] * [[:en-us_commands:reference:irtcsquarewave|IrtcSquareWave() View detailed description]] * [[:en-us_commands:reference:irtc32khz|Irtc32kHz() View detailed description]] [[:en-us_commands:builtin|← Built-in Command List]]