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

WBOY
Release: 2016-06-06 11:32:18
Original
1546 people have browsed it

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

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

#结果是: '4'

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

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!