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) {
@@ -145,17 +153,8 @@ Time ArduinoCellular::getGPSTime(){
145153}
146154
147155Time ArduinoCellular::getCellularTime (){
148- int year = 1970 ;
149- int month = 1 ;
150- int day = 1 ;
151- int hour = 0 ;
152- int minute = 0 ;
153- int second = 0 ;
154- float tz;
155- if (syncNTPServer () == 0 ) {
156- modem.getNetworkTime (&year, &month, &day, &hour, &minute, &second, &tz);
157- }
158- return Time (year, month, day, hour, minute, second);
156+ // Get the current time from the network as localtime
157+ return getTimeStruct (true );
159158}
160159
161160
0 commit comments