As you all know, (or so I believe) epoch time is the seconds since 1/1/1970.
It's easy to do, just multiply 31557600 (the number of seconds a year has) by the years between 1970 and the current year is that you're reading this. (in this case 2019).
I writted the algorithm in Python, and it works.
Now I port it to C, reading the year from CMOS, well you know.
Code: Select all
void epocht(void)
{
/*
Hardcoded, 'cause CMOS does not have an standard
register to century...
Anyways, I'll be dead when this century ends.
*/
int century = 20;
uint8_t year = get_rtcdate(9);
int fnyr;
/* Concatenates century and year in one integer */
fnyr = intcat(century, year);
println(nl"Year: ");
println(itoa(fnyr, buf, 10));
//fnyr = atoi(buf);
/* 1 year = 31557600 seconds */
int yrsec = 31557600;
/*
Epoch time starts at 1/1/1970 (DD/MM/YYYY)
How many years since 1970 and the actual year?
*/
int yrtn = 1970 - fnyr;
char buf9[255];
unsigned int i = 0;
while (i <= abs(yrtn))
{
/*
Formula 31557600 * years since 1970
*/
yrsec *= i;
++i;
}
println(nl"Epoch time: ");
println(itoa(yrsec, buf9, 10));
}
Well, the problem is that prints nothing, and another problem is that uint8_t year = get_rtcdate(9); returns 25, instead of the actual year.
It is weird because it was working before, I don't know what happened.
Thanks.