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

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

WBOY
WBOYOriginal
2016-06-06 11:32:181547browse

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

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

#结果是: '4'

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

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

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