Date, time, and more
Another very useful element that we can manage out of the box in Streamlit is date and time – that is, dates, hours, and so on.
For example, to print today’s date on the screen, we just have to write the following:
import datetime today = st.date_input("Today is",datetime.datetime.now())
Here, the first line simply imports the datetime
package while the second, using Streamlit’s date_input
, asks the user to select a date. This date will be saved in the today
variable:
Figure 3.34: The st.date_input widget
Continuing with date and time, we can do the same with time, as follows:
import time hour = st.time_input("The time is",datetime.time(12,30))
This time, we are importing time
and using time_input
, where we specify that the time is 12:30. On the screen, we can select any time we want:
Figure 3.35: The st.time_input widget
Streamlit is powerful and easy...