Reputation: 21
I would like to change my lcd 24 hours time format to 12 hours
import lcddriver
import time
import datetime
display = lcddriver.lcd()
try:
print("Writing to display")
display.lcd_display_string("Time", 1)
while True:
display.lcd_display_string(str(datetime.datetime.now().time()), 2)
except KeyboardInterrupt:
print("Cleaning up!")
display.lcd_clear()
Upvotes: 0
Views: 230
Reputation: 71689
You could use datetime
module in python like this:
import lcddriver
import time
import datetime
display = lcddriver.lcd()
try:
print("Writing to display")
display.lcd_display_string("Time", 1)
while True:
datestr = datetime.datetime.now().strftime("%I:%M:%S %p")
display.lcd_display_string(datestr, 2)
except KeyboardInterrupt:
print("Cleaning up!")
display.lcd_clear()
For example, if current time is 15:40:50 then datetime.datetime.now().strftime("%I:%M:%S %p")
outputs 03:40:50 PM
Hope it helps you!
Upvotes: 1