mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Calculating the day of week from a date
This commit is contained in:
@@ -11,6 +11,10 @@ This example is placed into the public domain.
|
||||
SoftI2C i2c(A4, A5);
|
||||
DS3232RTC rtc(i2c);
|
||||
|
||||
const char *days[] = {
|
||||
"Mon, ", "Tue, ", "Wed, ", "Thu, ", "Fri, ", "Sat, ", "Sun, "
|
||||
};
|
||||
|
||||
const char *months[] = {
|
||||
" Jan ", " Feb ", " Mar ", " Apr ", " May ", " Jun ",
|
||||
" Jul ", " Aug ", " Sep ", " Oct ", " Nov ", " Dec "
|
||||
@@ -52,6 +56,7 @@ void loop() {
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Date: ");
|
||||
Serial.print(days[RTC::dayOfWeek(&date) - 1]);
|
||||
Serial.print(date.day, DEC);
|
||||
Serial.print(months[date.month - 1]);
|
||||
Serial.print(date.year);
|
||||
|
||||
@@ -38,6 +38,10 @@ DS3232RTC rtc(i2c);
|
||||
char buffer[64];
|
||||
size_t buflen;
|
||||
|
||||
const char *days[] = {
|
||||
"Mon, ", "Tue, ", "Wed, ", "Thu, ", "Fri, ", "Sat, ", "Sun, "
|
||||
};
|
||||
|
||||
const char *months[] = {
|
||||
" Jan ", " Feb ", " Mar ", " Apr ", " May ", " Jun ",
|
||||
" Jul ", " Aug ", " Sep ", " Oct ", " Nov ", " Dec "
|
||||
@@ -192,6 +196,7 @@ void cmdDate(const char *args)
|
||||
|
||||
// Read the current date.
|
||||
rtc.readDate(&date);
|
||||
Serial.print(days[RTC::dayOfWeek(&date) - 1]);
|
||||
Serial.print(date.day, DEC);
|
||||
Serial.print(months[date.month - 1]);
|
||||
Serial.println(date.year, DEC);
|
||||
|
||||
Reference in New Issue
Block a user