import time def 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_time def pan(dt): return time.strptime(dt, '%Y-%m-%d').tm_yday a = inpu() b = pan(a) print('你輸入的日期爲當年的第%s天'%b) 結果: 輸入年份(年份需大於等於1970小於等於2038):2014 輸入月份:1 輸入日:31 你輸入的日期爲: 2014-1-31 你輸入的日期爲當年的第31天
python中利用Time模塊判斷輸入年月日爲該年第幾天
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.