File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 22
22
#include " TimeService.h"
23
23
24
24
#include < time.h>
25
-
25
+ #include < iomanip>
26
+ #include < sstream>
26
27
#include " NTPUtils.h"
27
28
28
29
/* *************************************************************************************
@@ -104,6 +105,19 @@ unsigned long TimeService::getLocalTime()
104
105
return utc + _timezone_offset;
105
106
}
106
107
108
+ unsigned long TimeService::getTimeFromString (const String& timeString)
109
+ {
110
+ struct tm t;
111
+ std::istringstream ss (timeString.c_str ());
112
+ ss >> std::get_time (&t, " %Y %b %d %H:%M:%S" );
113
+
114
+ if (!ss) {
115
+ return 0 ;
116
+ } else {
117
+ return mktime (&t);
118
+ }
119
+ }
120
+
107
121
/* *************************************************************************************
108
122
* PRIVATE MEMBER FUNCTIONS
109
123
**************************************************************************************/
Original file line number Diff line number Diff line change 23
23
**************************************************************************************/
24
24
25
25
#include < Arduino_ConnectionHandler.h>
26
+ #include < string>
26
27
27
28
28
29
#ifdef ARDUINO_ARCH_SAMD
@@ -49,6 +50,7 @@ class TimeService
49
50
unsigned long getTime ();
50
51
unsigned long getLocalTime ();
51
52
void setTimeZoneData (int offset, unsigned int valid_until);
53
+ static unsigned long getTimeFromString (const String& timeString);
52
54
53
55
private:
54
56
You can’t perform that action at this time.
0 commit comments