首页 > 代码库 > python脚本之日期格式显示
python脚本之日期格式显示
脚本内容:
#!/usr/bin/python
#coding=utf-8
#根据给定的年月日以数字形式打印出日期
months =[
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
#以1-31的数字作为结尾的列表
ending =["st","nd",‘rd‘]+17 * [‘th‘] \
+["st","nd","rd"]+7 * [‘th‘] \
+[‘st‘]
year =raw_input("year: ")
month =raw_input(‘month(1-12): ‘)
day =raw_input(‘day(1-31): ‘)
month_number =int(month)
day_number =int(day)
#记得要将月份和天数减1,以获得正确的索引
ordinal = day + ending[day_number-1]
month_name = months[month_number-1]
print month_name + ‘ ‘ +ordinal +‘,‘+year
效果:分别输入 年,月,日,得到我们想要的格式
python脚本之日期格式显示
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。