ESP8266 micropython 无法调整时区(timezone tzinfo)的处理办法

这个micropython是不错,编写也简单,上传也简单

但是 就这个简单的WIFI时钟却成了个麻烦 没法转换时区!默认都是UTC

 

咋办。。。。

放狗找了个大神的办法 好用

 

其思想就是把RTC时间加加加加! 反正这种东西也就是做个表,精度够了(至于夏令时之类的就。。。。反正+8区没夏令时。。。)

https://forum.micropython.org/viewtopic.php?t=3675



调整时区
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+8. 
# 1 hour = 3600 seconds
# 3 hours = 10800 seconds
tampon2=tampon1+8*60*60
# for second to convert time
#(year, month, mday, hour, minute, second, weekday, yearday)=utime.localtime(tampon2)
# first 0 = week of year
# second 0 = milisecond
#print(utime.localtime(tampon2))
#rtc.datetime((year, month, mday, 0, hour, minute, second, 0))
rtc.datetime ( utime.localtime(tampon2)[0:3] + (0,) + utime.localtime(tampon2)[3:6] + (0,))
time.localtime()

 

 

 

 

你可能感兴趣的:(ESP8266 micropython 无法调整时区(timezone tzinfo)的处理办法)