I have been using Flask to teach myself some coding and develop a web application for people with high blood pressure to track their daily blood pressure readings.

I wanted to find a way to automatically display the time when a user takes a blood pressure reading. It was quite simple.

Use strftime() to display Time and Date

The strftime() method returns a string displaying date and time using date, time or datetime object.

In your .py file you have to import time. Below are some examples to print time in different formats:

print (time.strftime("%H:%M:%S")) - Displays time in 24hr format.
print (time.strftime("%I:%M:%S")) - Displays time in 12hr format.

See more examples in the Python official documentation. Enjoy!

Grab a coffee mug from my sister website NYCmoments.nyc

Leave a comment

Your email address will not be published. Required fields are marked *