# Getting Local cell time

**URL:** <https://community.particle.io/t/getting-local-cell-time/52765>\
**Category:** General\
**Created:** [October 16, 2019, 8:12pm UTC](https://community.particle.io/t/getting-local-cell-time/52765 "2019-10-16T20:12:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack4566](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jack4566/32/14896_2.png) [@jack4566](https://community.particle.io/u/jack4566)\
**Post date:** [October 16, 2019, 8:12pm UTC](https://community.particle.io/t/getting-local-cell-time/52765/1 "2019-10-16T20:12:10Z")

</div>

Is there a method or possibility of getting time from the local cell tower like a cell phone does?

Having the user set a timezone is fine but I feel like the system should do this automatic.

---

<div class="post-metadata">

**Author:** ![armor](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/armor/32/18398_2.png) [@armor](https://community.particle.io/u/armor)\
**Post date:** [October 16, 2019, 10:31pm UTC](https://community.particle.io/t/getting-local-cell-time/52765/2 "2019-10-16T22:31:16Z")

</div>

> **[rwpalmer/TzCfg](https://github.com/rwpalmer/TzCfg)**
>
> Manages local time and DST settings for Particle IOT devices. Sets timezone based on the device's return IP address, by GPS coordinates, or by timezone ID. Data is obtained from public web-si...

This was posted by @shanevanj on a topic about Daylight Saving. There might be something here to apply to UTC to get local time.

---

<div class="post-metadata">

**Author:** ![shanevanj](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/shanevanj/32/21186_2.png) [@shanevanj](https://community.particle.io/u/shanevanj)\
**Post date:** [October 17, 2019, 4:09am UTC](https://community.particle.io/t/getting-local-cell-time/52765/3 "2019-10-17T04:09:48Z")

</div>

You could use a Particle.fucntion to set the lat, lon when a customer “registers” the installation ? I use a function that takes a 3 letter timezone code as an override in addition to the IP based auto detect just in case it doesn’t pick the correct zone

---

<div class="post-metadata">

**Author:** ![jack4566](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jack4566/32/14896_2.png) [@jack4566](https://community.particle.io/u/jack4566)\
**Post date:** [October 17, 2019, 4:14pm UTC](https://community.particle.io/t/getting-local-cell-time/52765/4 "2019-10-17T16:14:17Z")

</div>

Ok, after enabling +CTZU with Cellular.command() I got the Boron to spit out the local timezone based on the cell tower. My code is a bit ugly but it works for now.

```auto
SYSTEM_MODE(MANUAL);

char buffer[18] = "";
float zone;

void setup() {
  Serial.begin();
  while(!Serial){} //wait for Serial
  Cellular.on();
  if (RESP_OK == Cellular.command(callbackClock, buffer, 10000, "AT+CTZU=1\r\n")){ //This has to be set before cellular registration.
    Serial.println("+CTZU Success");
  }else{
    Serial.println("+CTZU Fail");
  }
  Particle.connect();
}

void loop() {
  Particle.process();
  if((millis() % 1000) == 0){
    if (RESP_OK == Cellular.command(callbackClock, buffer, 10000, "AT+CCLK?\r\n")){
      Serial.println(zone);
    }else{
      Serial.println("+CCLK Fail");
    }
  }
}

int callbackClock(int type, const char* buf, int len, char* buffer){
  char buffer2[18] = "";
  char buffer3[18] = "";
  sscanf(buf, "%[^\"]%*c%17s%3s\r\n", buffer, buffer2, buffer3);
  zone = ((((int)buffer3[1] - 48) * 10) + ((int)buffer3[2] - 48)) / 4;
  if (buffer3[0] == '-'){
    zone = -zone;
  }
  return RESP_OK;
}
int callbackZone(int type, const char* buf, int len, char* buffer){
  return RESP_OK;
}

```

And the output:  
`-6.00`

Which is correct! The Time Zone information is expressed in steps of 15 minutes so -24 = -6 which is MST.

I feel this should really be part of the core time library since +CTZU should work in most places.  
Also if anyone has some more robust code for sscanf I would appreciate it.

---

<div class="post-metadata">

**Author:** ![glx](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/glx/32/23129_2.png) [@glx](https://community.particle.io/u/glx)\
**Post date:** [October 17, 2019, 6:14pm UTC](https://community.particle.io/t/getting-local-cell-time/52765/5 "2019-10-17T18:14:29Z")

</div>

Ah nice, I tried that some time ago (with only AT+CCLK?) but that only replied an offset (since the modem was powered on) of the preset time.  
I’ll try that some time with the +CTZU command 🤔.  
By the way, is there a simple way to determine the next change of a daylightsaving? Even the google-api just tells the current state not the change-dates 🤔… I don’t want to lookup the time that often and maybe just store the dates and determine it locally.

Edit: I tried it and it sadly looks like my carrier (Vodafone in Germany) doesn’t support that feature 😢. It responds with success but the offset is always 0.
