Python语言与信息数据获取和机器学习

python 阳历转阴历代码(1)

2017-06-13  本文已影响0人  faraway_com

daysbetween.py

#!/usr/bin/python
#_*_coding:utf-8_*_

#计算两个日期之间的天数year/month/day 1991/12/14~2017/5/10

import datetime
import time


def days(date):
    date=date.split('/')
    if len(date)!=3:
        return False
    else:
        year=int(date[0])
        month=int(date[1])
        day=int(date[2])
        return year,month,day
'''
#输入两个时间计算相差多少天
def be_days(date0,date1):
    days1=datetime.date(days(date0)[0],days(date0)[1],days(date0)[2])
    days2=datetime.date(days(date1)[0],days(date1)[1],days(date1)[2])
    return abs(days2-days1)
    

date0=raw_input('please input a little date:\n>')
date1=raw_input('please input a big date:\n>')
print be_days(date0,date1)
'''

'''
#输入时间计算至今多少天
def be_days(date0):
    days1=datetime.date(days(date0)[0],days(date0)[1],days(date0)[2])
    days2=datetime.date.today()
    return abs(days2-days1)
    
    
date0=raw_input('please input a date:\n>')
print be_days(date0)
'''

#距离下一次过生日还有多少天
def be_days(date0,nextyear):
    days2=datetime.date(nextyear,days(date0)[1],days(date0)[2])
    days1=datetime.date.today()
    return abs(days2-days1)

#date0=raw_input('please input your birthday:\n>')
nextyear=int(time.strftime('%Y',time.localtime(time.time())))


def my_distance_DAY(date0):
    #be_days(date0,nextyear).split(',')[0]
    dat=str(be_days(date0,nextyear))
    return dat.split(',')[0]
上一篇下一篇

猜你喜欢

热点阅读