Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Date = datetime.datetime.today().strftime("%d %B %Y")
x = datetime.datetime.strptime(Date , "%d %B %Y")

returns:

2018-05-09 00:00:00

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
415 views
Welcome To Ask or Share your Answers For Others

1 Answer

A possible solution is to use str.lstrip

Ex:

import datetime
Date = datetime.datetime.today().strftime("%d %B %Y")
print(Date.lstrip("0"))

Output:

9 May 2018

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...