Created
February 18, 2022 13:45
-
-
Save DreamerDeLy/d0a1cd80e5dc695a1937113ef5f43f59 to your computer and use it in GitHub Desktop.
Parse ISO8601 like datetime string [Arduino]
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
// 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