]> vault307.fbx.one Git - RPI-PICO-I2C-LCD.git/commitdiff
Better date / time formatting
authorJános Rusiczki <janos.rusiczki@gmail.com>
Sat, 6 Mar 2021 20:19:02 +0000 (22:19 +0200)
committerGitHub <noreply@github.com>
Sat, 6 Mar 2021 20:19:02 +0000 (22:19 +0200)
Many thanks for putting together this library / short tutorial. It got me kickstarted with using a 20x4 LCD with my Pico.
Here's some giving back, instead of writing: `2021/3/6 3:8:2` it will write `2021/03/06 03:08:02`.

pico_i2c_lcd_test.py

index 89e2d96cad40d835d51e9064fdbed99f53d0b5cf..34fd9ffd82e708518206ffe96a7df81f78250709 100644 (file)
@@ -21,9 +21,9 @@ def test_main():
     while True:\r
         lcd.clear()\r
         time = utime.localtime()\r
-        lcd.putstr("{year}/{month}/{day} {HH}:{MM}:{SS}".format(\r
-            year=str(time[0]), month=str(time[1]), day=str(time[2]),\r
-            HH=str(time[3]), MM=str(time[4]), SS=str(time[5])))\r
+        lcd.putstr("{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}".format(\r
+            year=time[0], month=time[1], day=time[2],\r
+            HH=time[3], MM=time[4], SS=time[5]))\r
         if count % 10 == 0:\r
             print("Turning cursor on")\r
             lcd.show_cursor()\r