import time
x = input('请输入日期(yyyy-mm-dd):')
y = time.strptime(x, "%Y-%m-%d").tm_yday
print('%s 是这一年的第%d天' % (x, y))
程序源代码:
实例(Python 2.0+)
#!/usr/bin/python
# -*- coding: UTF-8 -*-
year = int(raw_input('year:\n'))
month = int(raw_input('month:\n'))
day = int(raw_input('day:\n'))
months = (0,31,59,90,120,151,181,212,243,273,304,334)
if 0 < month <= 12:
sum = months[month - 1]
else:
print 'data error'
sum += day
leap = 0
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
leap = 1
if (leap == 1) and (month > 2):
sum += 1
print 'it is the %dth day.' % sum
以上实例输出结果为:
year:
2015
month:
6
day:
7
it is the 158th day.
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。