python中利用Time模块判断输入年月日为该年第几天

来源:互联网 发布:中国音乐知乎 编辑:程序博客网 时间:2024/05/20 00:51
import timedef inpu():    the_year = int(input('输入年份(年份需大于等于1970小于等于2038):'))    if len(str(the_year)) == 4 and 1970 <= the_year <= 2038:        the_mon = int(input('输入月份:'))        if 1 <= the_mon <= 12:            the_day = int(input('输入日:'))            if 1 <= the_mon <= 31:                date_time = '%s-%s-%s' % (the_year, the_mon, the_day)                print('你输入的日期为:', date_time)    return date_timedef pan(dt):    return time.strptime(dt, '%Y-%m-%d').tm_ydaya = inpu()b = pan(a)print('你输入的日期为当年的第%s天'%b)结果:输入年份(年份需大于等于1970小于等于2038):2014输入月份:1输入日:31你输入的日期为: 2014-1-31你输入的日期为当年的第31天




阅读全文
0 0
原创粉丝点击