File tree Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change 1
1
#include < Arduino.h>
2
+ #include < time.h>
2
3
3
4
/* *
4
5
* @class Time
@@ -91,19 +92,35 @@ class Time {
91
92
* @return The time in UNIX timestamp format.
92
93
*/
93
94
String getUNIXTimestampString () {
94
- // Simple conversion to UNIX timestamp, not accounting for leap years or time zones
95
- long timestamp = second + minute*60 + hour*3600 + day*86400 + (month-1 )*2629743 + (year-1970 )*31556926 ;
96
- return String (timestamp);
95
+ return String (getUNIXTimestamp ());
97
96
}
98
97
99
98
/* *
100
99
* Returns the time in UNIX timestamp format.
101
100
* @return The time in UNIX timestamp format.
102
101
*/
103
102
unsigned long getUNIXTimestamp () {
104
- // Simple conversion to UNIX timestamp, not accounting for leap years or time zones
105
- unsigned long timestamp = second + minute*60 + hour*3600 + day*86400 + (month-1 )*2629743 + (year-1970 )*31556926 ;
106
- return timestamp;
103
+ struct tm t =
104
+ {
105
+ 0 /* tm_sec */ ,
106
+ 0 /* tm_min */ ,
107
+ 0 /* tm_hour */ ,
108
+ 0 /* tm_mday */ ,
109
+ 0 /* tm_mon */ ,
110
+ 0 /* tm_year */ ,
111
+ 0 /* tm_wday */ ,
112
+ 0 /* tm_yday */ ,
113
+ 0 /* tm_isdst */
114
+ };
115
+ t.tm_mon = month - 1 ;
116
+ t.tm_mday = day;
117
+ t.tm_year = year - 1900 ;
118
+ t.tm_hour = hour;
119
+ t.tm_min = minute;
120
+ t.tm_sec = second;
121
+ t.tm_isdst = -1 ;
122
+
123
+ return mktime (&t);
107
124
}
108
125
109
126
/* *
You can’t perform that action at this time.
0 commit comments