timezone support in MicroPython ?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
c.man
Posts: 21
Joined: Thu Jul 06, 2017 9:12 pm

timezone support in MicroPython ?

Post by c.man » Sat Aug 12, 2017 2:51 pm

Hi,
I need to store exact time and date for my city.
So, I inserted in boot.py the following code:

Code: Select all

from ntptime import settime
settime()
so, I can read time by:

Code: Select all

import utime
utime.localtime()

Isn't there a timezone support and legal/solar time support ?
How I to do ?

User avatar
deshipu
Posts: 1237
Joined: Thu May 28, 2015 5:54 pm

Re: timezone support in MicroPython ?

Post by deshipu » Sat Aug 12, 2017 5:07 pm

I'm afraid the timezones data required for such support would be about two orders of magnitude larger than the memory available on the microcontrollers supported by MicroPython.

vahithosan
Posts: 9
Joined: Wed Jul 26, 2017 5:15 pm

Re: timezone support in MicroPython ?

Post by vahithosan » Sat Aug 12, 2017 5:24 pm

c.man wrote:Hi,
I need to store exact time and date for my city.
So, I inserted in boot.py the following code:

Code: Select all

from ntptime import settime
settime()
so, I can read time by:

Code: Select all

import utime
utime.localtime()

Isn't there a timezone support and legal/solar time support ?
How I to do ?
I think . You will use rtc.

Code: Select all

import network
import time
import utime
import machine
from ntptime import settime

settime()
rtc=machine.RTC()

# for time convert to second
tampon1=utime.time() 
    
# for gmt. For me gmt+3. 
# 1 hour = 3600 seconds
# 3 hours = 10800 seconds
tampon2=tampon1+10800

# for second to convert time
(year, month, mday, hour, minute, second, weekday, yearday)=utime.localtime(tampon2)

# first 0 = week of year
# second 0 = milisecond
rtc.datetime((year, month, mday, 0, hour, minute, second, 0))

User avatar
c.man
Posts: 21
Joined: Thu Jul 06, 2017 9:12 pm

Re: timezone support in MicroPython ?

Post by c.man » Sat Aug 12, 2017 7:01 pm

deshipu wrote:I'm afraid the timezones data required for such support would be about two orders of magnitude larger than the memory available on the microcontrollers supported by MicroPython.
It would be enough to specify GMT (+1 for me: Rome) and legal/solar time in ntptime library.
Obviously you need to know what time zone you are referring to (now we are in legal time, so +1).
So effective time is +1 +1 +localtime

Post Reply