Python Forum

Full Version: use of format function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the following code, s is returned as an integer
The output is 1
How do I convert the integer s into a string with two decimal places.
i.e. I would like to print the month as 01 not 1
I assume I need a statement such as..
s = format(???????) before the print statement,.

import datetime
current_time = datetime.datetime.now()
s = current_time.month
print(s)
 
Like thiis:
import datetime
current_time = datetime.datetime.now()
s = current_time.month
print(f'{s:02}')
from datetime import datetime
print(datetime.now().strftime("%m"))