time_t is almost always the number of seconds (not counting leap seconds) since 00:00, Jan 1 1970 UTC (although is it not formally specified as such)
Category: DateTime
Set the RPi Time
Set the RPi Date and Time tm gps_date_time; char TimeString[128]; gps_date_time.tm_year = 20; gps_date_time.tm_mon = 1; gps_date_time.tm_mday = 1; gps_date_time.tm_hour = 1; gps_date_time.tm_min = 1; gps_date_time.tm_sec = 1; strftime(TimeString, 80, "%Y-%m-%dT%H:%M:%S", &gps_date_time); SetDataTimeString = "sudo date -s "; SetDataTimeString += TimeString; //Set the RPi time system((const char*)SetDataTimeString.c_str());
DateTime calculations
Calculate the difference between two struct tm values Adjusting tm values (add/subtract secs, mins, days, etc) Adjusting the struct tm values won’t cause roll overs (e.g. if you -100 from .tm_second you will get a negative .tm_second value), you get left with the values adjusted but a potentially out of range value. mktime() is used to convert […]
struct tm
A good way of storing and working with dates and time in C++. A structure containing a calendar date and time broken down into its components. Creating a tm #include <ctime> tm my_date_time; my_date_time.tm_year = (2015 – 1900); //years since 1900 (we must be >= 1970 for time_t based calcs) my_date_time.tm_mon = 1; //months since January […]
Get Current Time
For a tm Strict Loading current time into a tm struct – see here Get The Current Time And Display In A String #include <sys/time.h> static int seconds_last = 99; char TimeString[128]; timeval curTime; gettimeofday(&curTime, NULL); if (seconds_last == curTime.tv_sec) return; seconds_last = curTime.tv_sec; strftime(TimeString, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec)); timeval and gettimeofday gives you tvsec and tv_usec […]