This is a complete example showing how to read the system date and time, format it, and print it to the console. It uses the sys_date_get_now() to retrieve the current date and time.
static const char *days_of_week[] = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday"};
static const char *months_of_year[] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
uint16_t year;
uint8_t month, day, weekday;
return false;
} else {
sys_printf(
"%s %s %02u, %04u", days_of_week[weekday],
months_of_year[month - 1], day, year);
}
uint8_t hours, minutes, seconds;
return false;
} else {
sys_printf(
"%02u:%02u:%02u", hours, minutes, seconds);
}
} else {
}
return true;
}
static int iteration_count = 0;
static const int MAX_ITERATIONS = 60;
sys_printf(
"Iteration %d: ", iteration_count + 1);
printdate(&date);
} else {
sys_printf(
"Failed to get current date and time\n");
}
iteration_count++;
if (iteration_count >= MAX_ITERATIONS) {
}
}
int main() {
sys_printf(
"Clock example - running for %d iterations (1 per second)\n",
MAX_ITERATIONS);
return -1;
}
return 0;
}