Hi guys, I don’t know how many of you have tried using the RTC in Pokitto, but I seem to be having a little trouble.
From what I have googled, to set the date+time, the following code should work -
time_t asUnixTime(int year, int mon, int mday, int hour, int min, int sec) {
struct tm t;
t.tm_year = year - 1900;
t.tm_mon = mon;
t.tm_mday = mday;
t.tm_hour = hour;
t.tm_min = min;
t.tm_sec = sec;
t.tm_isdst = -1; // Is Daylight saving time on? 1 = yes, 0 = no, -1 = unknown
return mktime(&t); // returns seconds elapsed since January 1, 1970 (begin of the Epoch)
}
set_time(asUnixTime(2000,1,1,0,0,0)); // 2000, jan, 1st, 00:00:00
So, I set the time to 00:00:00 Jan 1st 2000. So far so good, when I display the clock all seems OK, both in my code and in the loader, the time is set correctly. However, with the following,
time_t pokTime = time(NULL);
const char *wDays[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
/*
tm_sec int seconds after the minute 0-60*
tm_min int minutes after the hour 0-59
tm_hour int hours since midnight 0-23
tm_mday int day of the month 1-31
tm_mon int months since January 0-11
tm_year int years since 1900
tm_wday int days since Sunday 0-6
tm_yday int days since January 1 0-365
tm_isdst int Daylight Saving Time flag
*/
char tempText[255];
struct tm tm = *localtime(&pokTime);
sprintf(tempText, "%s %2d/%2d/%2d", wDays[tm.tm_wday],tm.tm_mday, tm.tm_mon, (tm.tm_year + 1900)%100);
I get the day of the week as Tuesday, however, 1/1/2000 was a Saturday. (https://www.timeanddate.com/calendar/?year=2000)
Can anyone see, have I messed a step or something?