如何在Python中实现日历?

时间:2015-02-08 17:33:49

标签: python date calendar

例如,我将日期指定为:

2/12/2015

结果应为:

February/Thursday/2015

我尝试使用if,但我没有得到结果。如果你可以告诉我很长的路(不使用内置函数(如datetime和其他)太多),那将是很好的。我是蟒蛇新手,在我的学校里教的不多。

1 个答案:

答案 0 :(得分:4)

您不必使用datetime 太多,只需解析日期并以您想要的任何格式输出

from datetime import datetime

d = "2/12/2015"

print(datetime.strptime(d,"%m/%d/%Y").strftime("%B/%A/%Y"))
February/Thursday/2015

A = Locale’s full weekday name.
B =  Locale’s full month name.
Y = Year with century as a decimal number.

所有格式指令均为here

你可以创建一个dict映射,但你会发现datetime更简单。