Open fedcas opened 6 years ago
Maybe a bit late, but maybe useful for someone finding it:
Using time.h
(needs to be included) to convert to UNIX time
int32_t get_unix_time(){
// Create vars to hold the data
DateTime now;
struct tm time_struct;
time_t unix_time;
// Ask the clock for the data (or use any other DateTime-Object here)
now = Clock.read();
// modify the struct to the given date:
time_struct.tm_year = now.Year + 2000 - 1900; //RTC counts from 2000, UTC from 1900
time_struct.tm_mon = now.Month - 1; //months since January - [0,11]
time_struct.tm_mday = now.Day; //day of the month - [1,31]
time_struct.tm_hour = now.Hour; //hours since midnight - [0,23]
time_struct.tm_min = now.Minute; //minutes after the hour - [0,59]
time_struct.tm_sec = now.Second; //seconds after the minute - [0,59]
// create unix time stamp from struct and return it
return mktime(&time_struct);
}
Maybe a bit late, but thank you! :p
Hi, thanks for your library, it's the one that I'm using ;) there's just a couple of things I feel the need for.
A simple question: how can I print the timestamp in epoch format?
Thanks
P.S. opening a separate discussion for the second question ;)