Created
November 26, 2015 02:39
-
-
Save djohnson001/6df673a8d7f8ac04246a to your computer and use it in GitHub Desktop.
Convert an Arduino __DATE to YYYY-MM-DD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment