pdf-icon

UIFlow Guide

UIFlow 1.0 Project

NTP

Example

Read the current time through the network server, Note: When the program download offline, you need to add WiFi connection program before NTP initialization program, so that the device connects to the network.

from m5stack import *
from m5ui import *
from uiflow import *
import ntptime
import time

setScreenColor(0x222222)

ntp = ntptime.client(host='cn.pool.ntp.org', timezone=8)
while True:
  print(ntp.formatDatetime('-', ':'))
  print(ntp.getTimestamp())
  wait(1)
  wait_ms(2)

API

import ntptime
ntp = ntptime.client(host='cn.pool.ntp.org', timezone=8)
  • Set the NTP server and time zone, and connect.
    • host:
      • cn.pool.ntp.org
      • jp.pool.ntp.org
      • sg.pool.ntp.org
      • tw.pool.ntp.org
      • hk.pool.ntp.org
      • us.pool.ntp.org
      • de.pool.ntp.org
ntp.formatDate('-')
  • Retrieve the current date and set the delimiter.
ntp.formatTime(':')
  • Retrieve the current time and set the separator.
ntp.formatDatetime('-', ':')
  • Read the current date and time, and set the date format separator and time format separator.
ntp.getTimestamp()
  • Retrieve the current Unix timestamp
ntp.year()
  • Read current year
ntp.month()
  • Read current month
ntp.weekday()
  • Retrieve the current day of the week
  • return value:
    • Sunday:0
    • Monday:1
    • Tuesday:2
    • Wednesday:3
    • Thursday:4
    • Friday:5
    • Saturday:6
ntp.day()
  • Read current day
ntp.hour()
  • Read current hour
ntp.minute()
  • Read current minute
ntp.second()
  • Read current second
On This Page