日期时间-Strftime和Strptime [英] Datetime - Strftime and Strptime
本文介绍了日期时间-Strftime和Strptime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Date = datetime.datetime.today().strftime("%d %B %Y")
x = datetime.datetime.strptime(Date , "%d %B %Y")
返回:
2018-05-09 00:00:00
代替:2018年5月9日,我在做什么错?本质上,我试图获取我搜索过的strftime的非零填充版本,并且我读到解决该问题的方法是strptime.
instead of: 9 May 2018, what am I doing wrong? Essentially I am trying to get the non zero padded version of strftime for which I searched around and I read that the way to go about it is strptime.
推荐答案
一种可能的解决方案是使用 str.lstrip
A possible solution is to use str.lstrip
例如:
import datetime
Date = datetime.datetime.today().strftime("%d %B %Y")
print(Date.lstrip("0"))
输出:
9 May 2018
这篇关于日期时间-Strftime和Strptime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文