为了账号安全,请及时绑定邮箱和手机立即绑定

如何将此日期格式化为日 - 月 - 年

如何将此日期格式化为日 - 月 - 年

温温酱 2022-08-02 10:48:13
def UpdateDate(WorstDate):    Day = WorstDate[5:]    Month = WorstDate[2:6]    Year = WorstDate[:2]    return Day + "-" + Month + "-" + Yearprint(UpdateDate("202011Jan"))我不断得到(1Jan-2011-20)我不是专业人士,所以任何建议将不胜感激。
查看完整描述

2 回答

?
茅侃侃

TA贡献1842条经验 获得超22个赞

这可能很有用:


import time


timestr = time.strftime("%d-%m-%Y")


print(timestr)


查看完整回答
反对 回复 2022-08-02
?
凤凰求蛊

TA贡献1825条经验 获得超4个赞

以下是更新的解决方案:



    def UpdateDate(WorstDate):

        Day = WorstDate[4:6]

        Month = WorstDate[6:]

        Year = WorstDate[:4]

        return Day + "-" + Month + "-" + Year


    print(UpdateDate("202011Jan"))



输出:


11-Jan-2020


查看完整回答
反对 回复 2022-08-02
  • 2 回答
  • 0 关注
  • 106 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号