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

Python datetime time formatting removes leading 0s

高洛峰
Release: 2017-01-12 15:15:58
Original
2518 people have browsed it

When formatting Python time, remove the leading 0:

dt = datetime.now()
print dt.strftime('%-H')
Copy after login

#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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template