Convert to unix time


I have an electron and after many hours of searching and reading cant figure out how to convert take a cracked date/time (i.e. year, month, day, hour, minute, second) and turn that into unix epoch time.

you can use the mktime() function… like in this function call:

unsigned int myTime = tmConvert_t(Time.year(), Time.month(),, Time.hour(), Time.minute(), Time.second());


time_t tmConvert_t(int YYYY, byte MM, byte DD, byte hh, byte mm, byte ss)  // inlined for speed
  struct tm t;
  t.tm_year = YYYY-1900;
  t.tm_mon = MM - 1;
  t.tm_mday = DD;
  t.tm_hour = hh;
  t.tm_min = mm;
  t.tm_sec = ss;
  t.tm_isdst = 0;  // not used
  time_t t_of_day = mktime(&t);
  return t_of_day;


1 Like