本文整理汇总了Python中utime.localtime方法的典型用法代码示例。如果您正苦于以下问题:Python utime.localtime方法的具体用法?Python utime.localtime怎么用?Python utime.localtime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utime
的用法示例。
在下文中一共展示了utime.localtime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_time
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def _do_time(self, action): # TIME received from ESP8266
lnk = self._lnk
try:
t = int(action[0])
except ValueError: # Gibberish.
lnk.quit('Invalid data from ESP8266')
return
self._time_valid = t > 0
if self._time_valid:
rtc = pyb.RTC()
tm = localtime(t)
hours = (tm[3] + self._local_time_offset) % 24
tm = tm[0:3] + (tm[6] + 1,) + (hours,) + tm[4:6] + (0,)
rtc.datetime(tm)
self._rtc_last_syn = time()
lnk.vbprint('time', localtime())
else:
lnk.vbprint('Bad time received.')
# Is Pyboard RTC synchronised?
示例2: perform
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def perform(self) :
localtime = self.get_localtime()
secs = Scheduler.secs_since_midnight(localtime)
(_year, _month, _mday, _hour, _minute, _second, wday, _yday) = localtime
seq = self.get_current_seq(secs, wday + 1)
if seq :
if seq != self.current_seq :
color_name = seq['color_name']
logging.info("Scheduler: Setting lamp color to {}", color_name)
self.lamp.set_colorspec(self.color_specs[color_name])
self.current_seq = seq
else :
self.lamp.set_colorspec(self.color_specs['black'])
self.current_seq = None
return True
##
## Internal operations
##
示例3: aclock
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def aclock():
uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi
pi = cmath.pi
days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
'Sunday')
months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
# Instantiate CWriter
CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
wri.set_clip(True, True, False)
# Instantiate displayable objects
dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False) # Border in fg color
lbltim = Label(wri, 5, 85, 35)
hrs = Pointer(dial)
mins = Pointer(dial)
secs = Pointer(dial)
hstart = 0 + 0.7j # Pointer lengths and position at top
mstart = 0 + 0.92j
sstart = 0 + 0.92j
while True:
t = utime.localtime()
hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW)
mins.value(mstart * uv(-t[4] * pi/30), YELLOW)
secs.value(sstart * uv(-t[5] * pi/30), RED)
lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
refresh(ssd)
utime.sleep(1)
示例4: printtime
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def printtime():
print('{:02d}:{:02d}:{:02d} '.format(localtime()[3], localtime()[4], localtime()[5]), end='')
示例5: time
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def time():
NTP_QUERY = bytearray(48)
NTP_QUERY[0] = 0x1b
addr = socket.getaddrinfo(host, 123)[0][-1]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(1)
res = s.sendto(NTP_QUERY, addr)
msg = s.recv(48)
s.close()
val = struct.unpack("!I", msg[40:44])[0]
return val - NTP_DELTA
# There's currently no timezone support in MicroPython, so
# utime.localtime() will return UTC time (as if it was .gmtime())
示例6: settime
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def settime():
t = time()
import machine
import utime
tm = utime.localtime(t)
tm = tm[0:3] + (0,) + tm[3:6] + (0,)
machine.RTC().datetime(tm)
print(utime.localtime())
示例7: convert
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def convert(self, set_rtc=False): # Return a tuple in localtime() format (less yday)
data = self.timebuf
ss = bcd2dec(data[0])
mm = bcd2dec(data[1])
if data[2] & 0x40:
hh = bcd2dec(data[2] & 0x1f)
if data[2] & 0x20:
hh += 12
else:
hh = bcd2dec(data[2])
wday = data[3]
DD = bcd2dec(data[4])
MM = bcd2dec(data[5] & 0x1f)
YY = bcd2dec(data[6])
if data[5] & 0x80:
YY += 2000
else:
YY += 1900
# Time from DS3231 in time.localtime() format (less yday)
result = YY, MM, DD, hh, mm, ss, wday -1, 0
if set_rtc:
if rtc is None:
# Best we can do is to set local time
secs = utime.mktime(result)
utime.localtime(secs)
else:
rtc.datetime((YY, MM, DD, wday, hh, mm, ss, 0))
return result
示例8: save_time
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def save_time(self):
(YY, MM, mday, hh, mm, ss, wday, yday) = utime.localtime() # Based on RTC
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 0, tobytes(dec2bcd(ss)))
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 1, tobytes(dec2bcd(mm)))
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 2, tobytes(dec2bcd(hh))) # Sets to 24hr mode
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 3, tobytes(dec2bcd(wday + 1))) # 1 == Monday, 7 == Sunday
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 4, tobytes(dec2bcd(mday))) # Day of month
if YY >= 2000:
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 5, tobytes(dec2bcd(MM) | 0b10000000)) # Century bit
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 6, tobytes(dec2bcd(YY-2000)))
else:
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 5, tobytes(dec2bcd(MM)))
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 6, tobytes(dec2bcd(YY-1900)))
# Wait until DS3231 seconds value changes before reading and returning data
示例9: save_time
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def save_time(self):
(YY, MM, mday, hh, mm, ss, wday, yday) = utime.localtime() # Based on RTC
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 0, tobytes(dec2bcd(ss)))
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 1, tobytes(dec2bcd(mm)))
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 2, tobytes(dec2bcd(hh))) # Sets to 24hr mode
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 3, tobytes(dec2bcd(wday + 1))) # 1 == Monday, 7 == Sunday
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 4, tobytes(dec2bcd(mday))) # Day of month
if YY >= 2000:
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 5, tobytes(dec2bcd(MM) | 0b10000000)) # Century bit
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 6, tobytes(dec2bcd(YY-2000)))
else:
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 5, tobytes(dec2bcd(MM)))
self.ds3231.writeto_mem(DS3231_I2C_ADDR, 6, tobytes(dec2bcd(YY-1900)))
示例10: set_time
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def set_time():
ntptime.settime()
tm = utime.localtime()
tm = tm[0:3] + (0,) + tm[3:6] + (0,)
machine.RTC().datetime(tm)
print('current time: {}'.format(utime.localtime()))
示例11: set_datetime
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def set_datetime(secs) :
import utime
import machine
tm = utime.localtime(secs)
tm = tm[0:3] + (0,) + tm[3:6] + (0,)
machine.RTC().datetime(tm)
示例12: get_datetime
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def get_datetime() :
import time
year, month, day, hour, minute, second, millis, _tzinfo = time.localtime()
return "%d-%02d-%02dT%02d:%02d:%02d.%03d" % (year, month, day, hour, minute, second, millis)
示例13: datetime_str
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def datetime_str(localtime) :
(year, month, day, hour, minute, second, millis, _tzinfo) = localtime
return "%d-%02d-%02dT%02d:%02d:%02d.%03d" % (year, month, day, hour, minute, second, millis)
示例14: get_localtime
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def get_localtime(raw=False):
import utime
localtime = utime.localtime()
if raw:
return utime.mktime(localtime)
else:
return DateTimeCmd.datetime_str(localtime)
示例15: get_datetime_from_secs
# 需要导入模块: import utime [as 别名]
# 或者: from utime import localtime [as 别名]
def get_datetime_from_secs(secs):
import utime
tm = utime.localtime(secs)
return DateTimeCmd.datetime_str(tm)