Getting the unix seconds for the next 24 hours in future?

I’m trying to find the unix epoch seconds for the next 24 hours in the future and having some trouble. If I could even find the unix seconds of the next hour I should be able to find the hours in the future, but so far I haven’t been able to do so.

Here’s the code I’m using:

// include header file for time function
#include <TimeLib.h>

// the RTC
#include "RTClib.h"

void setup() {

void loop()  {

  //DateTime now =;

  // Tuesday, October 29, 2019 9:38:19 PM
  DateTime now=1572385099; 

  for (int i = 0; i <= 24; i++) {

    tmElements_t tm;

    tm.Second = 0;
    tm.Hour = 0;
    tm.Minute = 0;
    tm.Day = now.hour();
    tm.Day =;
    tm.Month = now.month();
    tm.Year = now.year();
    time_t nextMakeTime =  makeTime(tm); 



The DateTime is part of the RTC library, and is just unix seconds.

The above code returns -1400417792 for the nextMakeTime, which is odd.

I don’t imagine anyone has any ideas?

Aha, fixed by subtracting 1970 from the year:

tm.Year = now.year()-1970;

I'm planning to then add 3600 seconds to each hour to get 24 hours into the future, and then convert those seconds to unix timestamps.

If anyone sees a more efficient way of doing so, please let me know.

1 day = 86400 seconds:

unsigned long secPerDay = 86400UL;
tomorrow = DateTime now + secPerDay;

TimeLib has constants like SECS_PER_DAY

here are some snippets working with TimeLib and C time functions