File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -91,19 +91,35 @@ class Time {
91
91
* @return The time in UNIX timestamp format.
92
92
*/
93
93
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);
94
+ return String (getUNIXTimestamp ());
97
95
}
98
96
99
97
/* *
100
98
* Returns the time in UNIX timestamp format.
101
99
* @return The time in UNIX timestamp format.
102
100
*/
103
101
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;
102
+ struct tm t =
103
+ {
104
+ 0 /* tm_sec */ ,
105
+ 0 /* tm_min */ ,
106
+ 0 /* tm_hour */ ,
107
+ 0 /* tm_mday */ ,
108
+ 0 /* tm_mon */ ,
109
+ 0 /* tm_year */ ,
110
+ 0 /* tm_wday */ ,
111
+ 0 /* tm_yday */ ,
112
+ 0 /* tm_isdst */
113
+ };
114
+ t.tm_mon = month - 1 ;
115
+ t.tm_mday = day;
116
+ t.tm_year = year - 1900 ;
117
+ t.tm_hour = hour;
118
+ t.tm_min = minute;
119
+ t.tm_sec = second;
120
+ t.tm_isdst = -1 ;
121
+
122
+ return mktime (&t);
107
123
}
108
124
109
125
/* *
You can’t perform that action at this time.
0 commit comments