Home > Backend Development > Python Tutorial > Python datetime时间格式化去掉前导0

Python datetime时间格式化去掉前导0

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 11:32:18
Original
1664 people have browsed it

Python时间格式化的时候,去掉前导0的:

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

#结果是: '4'

在format string的%与flag之间,添加一个“-”即可。

在Mac和Linux中试过可用,不确定是否可以移植。

Related labels:
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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template