Page 1 of 1

oled date display

Posted: Tue Apr 20, 2021 7:41 am
by wonde05
HI GUYS , can any one tell me how i can display the day as (21-04-20) not (2021-04-20). am using the code below with esp32 .

Code: Select all

from machine import Pin, I2C
import SSD1306
from time import sleep
from machine import RTC

i2c = I2C(-1, scl=Pin(22), sda=Pin(21), freq=10000)
oled_width = 128
oled_height = 64
oled = SSD1306.SSD1306_I2C(oled_width, oled_height, i2c)

rtc = RTC()
rtc.datetime((2021, 2, 10, 3, 11, 30, 0, 0))



isPoint = True
t = rtc.datetime() 
oled.fill(0) 
oled.text('{}-{:02d}-{:02d}' .format(t[0],t[1],t[2]),0, 0)  
if isPoint: 
    colon = ':' 
else: 
    colon = ' ' 
oled.text(' {:02d}{}{:02d}' .format(t[4], colon, t[5]), 80, 0) 
oled.show() 
isPoint = not isPoint
 

Re: oled date display

Posted: Tue Apr 20, 2021 12:11 pm
by pythoncoder
Try this format string

Code: Select all

'{:02d}-{:02d}-{:02d}'.format(t[0] - 2000,t[1],t[2])

Re: oled date display

Posted: Wed Apr 21, 2021 5:32 am
by wonde05
Thanks.