从2019年2月4日更改日期格式,直到2月4日

问题描述 投票:0回答:1

我有一个电子纸架python脚本。我想从“2019年2月4日”的日期更改为“04 2”来代替。我一直在调整了几个小时的代码,我不能让它开始工作。

代码如下所示:

# Calendar strings to be displayed
day_str = time.strftime("%A")
day_number = time.strftime("%d")
month_str = time.strftime("%B") + ' ' + time.strftime("%Y")
month_cal = str(calendar.month(int(time.strftime("%Y")), int(time.strftime("%m"))))
month_cal = month_cal.split("\n",1)[1];
update_moment = time.strftime("%H") + ':' + time.strftime("%M")
python raspberry-pi
1个回答
1
投票
d = '2019-02-04'
datetime.strptime(d, '%Y-%m-%d').strftime('%d %b')

产量

'04 Feb'
© www.soinside.com 2019 - 2024. All rights reserved.