55 #include " Watchdog.h"
66#endif
77
8- unsigned long ArduinoCellular::getTime ( ) {
8+ Time ArduinoCellular::getTimeStruct ( bool localTime ) {
99 int year = 1970 ;
1010 int month = 1 ;
1111 int day = 1 ;
@@ -14,9 +14,17 @@ unsigned long ArduinoCellular::getTime() {
1414 int second = 0 ;
1515 float tz;
1616 if (syncNTPServer () == 0 ) {
17- modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
17+ if (localTime) {
18+ modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
19+ } else {
20+ modem.getNetworkUTCTime (&year, &month, &day, &hour, &minute, &second, &tz);
21+ }
1822 }
19- return Time (year, month, day, hour, minute, second).getUNIXTimestamp ();
23+ return Time (year, month, day, hour, minute, second);
24+ }
25+
26+ unsigned long ArduinoCellular::getTime () {
27+ return getTimeStruct ().getUNIXTimestamp ();
2028}
2129
2230int ArduinoCellular::syncNTPServer (bool forceNTPSync) {
@@ -146,17 +154,8 @@ Time ArduinoCellular::getGPSTime(){
146154}
147155
148156Time ArduinoCellular::getCellularTime (){
149- int year = 1970 ;
150- int month = 1 ;
151- int day = 1 ;
152- int hour = 0 ;
153- int minute = 0 ;
154- int second = 0 ;
155- float tz;
156- if (syncNTPServer () == 0 ) {
157- modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
158- }
159- return Time (year, month, day, hour, minute, second);
157+ // Get the current time from the network as localtime
158+ return getTimeStruct (true );
160159}
161160
162161
0 commit comments