猿问

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


def UpdateDate(WorstDate):

    Day = WorstDate[5:]

    Month = WorstDate[2:6]

    Year = WorstDate[:2]

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

print(UpdateDate("202011Jan"))

我不断得到(1Jan-2011-20)我不是专业人士,所以任何建议将不胜感激。


温温酱
浏览 107回答 2
2回答

茅侃侃

这可能很有用:import timetimestr = time.strftime("%d-%m-%Y")print(timestr)

凤凰求蛊

以下是更新的解决方案:    def UpdateDate(WorstDate):        Day = WorstDate[4:6]        Month = WorstDate[6:]        Year = WorstDate[:4]        return Day + "-" + Month + "-" + Year    print(UpdateDate("202011Jan"))输出:11-Jan-2020
随时随地看视频慕课网APP

相关分类

Python
我要回答