码迷,mamicode.com
首页 > 编程语言 > 详细

python脚本之日期格式显示

时间:2017-08-04 16:44:47      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:print   apr   年月日   pytho   usr   索引   ima   int   logs   

脚本内容:

#!/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脚本之日期格式显示

标签:print   apr   年月日   pytho   usr   索引   ima   int   logs   

原文地址:http://www.cnblogs.com/to-be-rich/p/7285877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!