Skip to content

Instantly share code, notes, and snippets.

@DreamerDeLy
Created February 18, 2022 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DreamerDeLy/d0a1cd80e5dc695a1937113ef5f43f59 to your computer and use it in GitHub Desktop.
Save DreamerDeLy/d0a1cd80e5dc695a1937113ef5f43f59 to your computer and use it in GitHub Desktop.
Parse ISO8601 like datetime string [Arduino]
// Data string
String time_string = "2021-12-12 18:55:54";
// Parsing
int year = time_string.substring(0, 4).toInt();
int month = time_string.substring(5, 7).toInt();
int day = time_string.substring(8, 10).toInt();
int hour = time_string.substring(11, 13).toInt();
int minute = time_string.substring(14, 16).toInt();
int second = time_string.substring(17, 19).toInt();
// Creating DateTime object
DateTime new_time = DateTime(year, month, day, hour, minute, second);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment