From 5538558c7c26e3ce14a8a9636dce83651ca3ba2b Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 16 Aug 2023 22:03:50 +0300 Subject: [PATCH] arduino __DATE__ --- snipplets/code/Arduino/compile_date_time.c | 7 +++++++ .../code/Arduino/convert_DATE_to_YYYY-MM-DD.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 snipplets/code/Arduino/compile_date_time.c create mode 100644 snipplets/code/Arduino/convert_DATE_to_YYYY-MM-DD.c diff --git a/snipplets/code/Arduino/compile_date_time.c b/snipplets/code/Arduino/compile_date_time.c new file mode 100644 index 0000000..21df4a5 --- /dev/null +++ b/snipplets/code/Arduino/compile_date_time.c @@ -0,0 +1,7 @@ +void loop() { + Serial.println("Built: " __DATE__ " | " __TIME__); + /** + * Example show: + * Built: Aug 16 2023 | 21:42:32 + */ +} diff --git a/snipplets/code/Arduino/convert_DATE_to_YYYY-MM-DD.c b/snipplets/code/Arduino/convert_DATE_to_YYYY-MM-DD.c new file mode 100644 index 0000000..22eeec7 --- /dev/null +++ b/snipplets/code/Arduino/convert_DATE_to_YYYY-MM-DD.c @@ -0,0 +1,18 @@ +// Adapted from http://stackoverflow.com/questions/1765014/convert-string-from-date-into-a-time-t +// Formats __DATE__ to YYYY-MM-DD format +String ArduinoDateToDisplayDate(char const *time) { + char s_month[5]; + int month, day, year; + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + sscanf(time, "%s %d %d", s_month, &day, &year); + + month = (strstr(month_names, s_month)-month_names)/3; + + String monthText = month < 10 ? "0" + String(month) : String(month); + String dayText = day < 10 ? "0" + String(day) : String(day); + + return String(year) + "-" + monthText + "-" + dayText; +} + +// https://gist.github.com/djohnson001/6df673a8d7f8ac04246a