@@ -210,3 +210,66 @@ void NTPClient::setRandomPort(unsigned int minValue, unsigned int maxValue) {
210
210
randomSeed (analogRead (0 ));
211
211
this ->_port = random (minValue, maxValue);
212
212
}
213
+
214
+
215
+ void NTPClient::setEpochTime (unsigned long secs) {
216
+ this ->_currentEpoc = secs;
217
+ }
218
+
219
+ String NTPClient::getFullFormattedTime (unsigned long secs)
220
+ {
221
+ time_t rawtime = this ->getEpochTime ();
222
+ struct tm *ti;
223
+ ti = localtime (&rawtime);
224
+
225
+ uint16_t year = ti->tm_year + 1900 ;
226
+ String yearStr = String (year);
227
+
228
+ uint8_t month = ti->tm_mon + 1 ;
229
+ String monthStr = month < 10 ? " 0" + String (month) : String (month);
230
+
231
+ uint8_t day = ti->tm_mday ;
232
+ String dayStr = day < 10 ? " 0" + String (day) : String (day);
233
+
234
+ uint8_t hours = ti->tm_hour ;
235
+ String hoursStr = hours < 10 ? " 0" + String (hours) : String (hours);
236
+
237
+ uint8_t minutes = ti->tm_min ;
238
+ String minuteStr = minutes < 10 ? " 0" + String (minutes) : String (minutes);
239
+
240
+ uint8_t seconds = ti->tm_sec ;
241
+ String secondStr = seconds < 10 ? " 0" + String (seconds) : String (seconds);
242
+
243
+ return yearStr + " -" + monthStr + " -" + dayStr + " T" +
244
+ hoursStr + " :" + minuteStr + " :" + secondStr + " Z" ;
245
+ }
246
+
247
+ int NTPClient::getYear ()
248
+ {
249
+ time_t rawtime = this ->getEpochTime ();
250
+ struct tm *ti;
251
+ ti = localtime (&rawtime);
252
+ int year = ti->tm_year + 1900 ;
253
+
254
+ return year;
255
+ }
256
+
257
+ int NTPClient::getMonth ()
258
+ {
259
+ time_t rawtime = this ->getEpochTime ();
260
+ struct tm *ti;
261
+ ti = localtime (&rawtime);
262
+ int month = (ti->tm_mon + 1 ) < 10 ? 0 + (ti->tm_mon + 1 ) : (ti->tm_mon + 1 );
263
+
264
+ return month;
265
+ }
266
+
267
+ int NTPClient::getDate ()
268
+ {
269
+ time_t rawtime = this ->getEpochTime ();
270
+ struct tm *ti;
271
+ ti = localtime (&rawtime);
272
+ int month = (ti->tm_mday ) < 10 ? 0 + (ti->tm_mday ) : (ti->tm_mday );
273
+
274
+ return month;
275
+ }
0 commit comments