Current time in a specific timezone


If you are asking a question, please follow this template:

  1. My goal is: to fetch current time and run a job on a specific time.
  2. My actions are: I have included SNTP library in mos.yml and invoked function to fetch current time
  3. The result I see is: I see the time shown is the time elapsed since ESP8266 has started
  4. My expectation & question is: I am expecting to get the current time in my timezone so that I can use crontabs to schedule the job. How can I get current time in India timezone?

In order to synchronize the time using sntp, your device must have internet connection.

To get the local time you have to add sys.tz_spec in your mos.yml

A simpler way to do this is provided by @mamuesp’s timezones library.


@nliviu, thanks a lot. I had set wifi credentials using mos command line tool. I was not aware that if you flash the app again, then configuration needs to be set once again. I was able to solve this problem by setting wifi credentials and SNTP timezone information in mos.yml. Thanks a lot for your help.

1 Like

After flashing the firmware the first time, you can OTA update it and conf9.json (ie. the device configuration changed with mos --port <your_port> config-set, mos wifi) will be preserved between updates.