Home  >  Article  >  Backend Development  >  Python datetime time formatting removes leading 0s

Python datetime time formatting removes leading 0s

高洛峰
高洛峰Original
2017-01-12 15:15:582402browse

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!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn