Home > Article > Backend Development > Python datetime time formatting removes leading 0s
When formatting Python time, remove the leading 0:
dt = datetime.now() print dt.strftime('%-H')
#The result is: '4'
Between % and flag of format string , just add a "-".
Tried to work on Mac and Linux, not sure if it can be ported.
For more articles related to Python datetime time formatting to remove leading 0s, please pay attention to the PHP Chinese website!