Make epoch timestamp: makeTime( ) [Solved]

looking to compare Unix epoch timestamps… Is there a function/library available to do something like how I would do it on Arduino:


#include <Time.h>

time_t tmConvert_t(int YYYY, byte MM, byte DD, byte hh, byte mm, byte ss)
{
  tmElements_t tmSet;
  tmSet.Year = YYYY - 1970;
  tmSet.Month = MM;
  tmSet.Day = DD;
  tmSet.Hour = hh;
  tmSet.Minute = mm;
  tmSet.Second = ss;
  return makeTime(tmSet); 
}
void setup()
{
  Serial.begin(9600);
  time_t s_tm = tmConvert_t(2015,2,15,7,30,00);
  Serial.println(s_tm);
}

void loop()
{
}

got it:

#include <time.h>

struct tm t;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  time_t t_of_day;
  t.tm_year = 2015-1900;
  t.tm_mon = 2;           // Month, 0 - jan
  t.tm_mday = 15;          // Day of the month
  t.tm_hour = 3;
  t.tm_min = 0;
  t.tm_sec = 0;
  t.tm_isdst = -1;        // Is DST on? 1 = yes, 0 = no, -1 = unknown
  t_of_day = mktime(&t);
  Serial.println(t_of_day);
  delay(5000);
}
2 Likes

See: http://docs.spark.io/firmware/#other-functions-time

Or perhaps something like this could work: http://docs.spark.io/firmware/#libraries-time

thanks but I need epoch timestamp for this project

thanks,

the snippet above solved the problem, Spark has an implementation of mktime( ) which I didn't expect!

3 Likes