Leo*_*kus 1 format time micropython raspberry-pi-pico
我正在尝试使用 Raspberry Pi Pico 和 MicroPython 转换time.localtime()为字符串。我尝试过.join(),但 Raspberry Pi Pico 运行 MicroPython:
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
now = time.localtime()
print("Current date and time: ")
print(now)
w = 128
h = 32
i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=200000)
addr = i2c.scan()[0]
oled = SSD1306_I2C(w, h, i2c, addr)
oled.fill(0)
oled.text("Raspberry Pi ", 5, 5)
olex.text("Hi Leo", 5, 15)
oled.show()
Run Code Online (Sandbox Code Playgroud)
import time
now = time.localtime()
print("Date: {}/{}/{}".format(now[1], now[2], now[0]))
print("Time: {}:{}".format(now[3], now[4]))
Run Code Online (Sandbox Code Playgroud)
您的变量now具有所有必需的数据 - 它由元组组成
(年、月、日、时、分、秒、工作日、年日)
此处提供文档