oled date display

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

oled date display

Post by wonde05 » Tue Apr 20, 2021 7:41 am

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
 

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: oled date display

Post by pythoncoder » Tue Apr 20, 2021 12:11 pm

Try this format string

Code: Select all

'{:02d}-{:02d}-{:02d}'.format(t[0] - 2000,t[1],t[2])
Peter Hinch
Index to my micropython libraries.

wonde05
Posts: 26
Joined: Thu Apr 08, 2021 12:53 pm

Re: oled date display

Post by wonde05 » Wed Apr 21, 2021 5:32 am

Thanks.

Post Reply