MrLunk

ESP8266 - Micropython - Network Time Server Sync + timezone correction

Jan 28th, 2021 (edited)
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.32 KB | None | 0 0
  1. import ntptime
  2. import machine
  3. import utime
  4.  
  5. ntptime.settime()
  6. rtc = machine.RTC()
  7.  
  8. #Timezone Correction value -12 to +12
  9. utc_shift = 1
  10.  
  11. tm = utime.localtime(utime.mktime(utime.localtime()) + utc_shift*3600)
  12. tm = tm[0:3] + (0,) + tm[3:6] + (0,)
  13. rtc.datetime(tm)
  14.  
  15. TimeNow = rtc.datetime()
  16.  
  17. print("Time Now:",TimeNow)
  18.  
Add Comment
Please, Sign In to add comment