1 获取本机ip
import socket
ip = socket.gethostbyname(socket.gethostname())
2 统一格式:十进制和日期
def get_standard_data(data):
all_data=[]
for one in data:
_one=[]
for i in one:
if type(i).__name__=='Decimal':
i=float(i)
elif type(i).__name__=='datetime':
i = i.strftime('%Y-%m-%d %H:%M:%S')
_one.append(i)
all_data.append(_one)
return all_data
3 计算一个月后的日期
安装:pip install python-dateutil
使用方法:
# 前一个月
import datetime
from dateutil.relativedelta import relativedelta
if __name__ == "__main__":
print(datetime.date.today() - relativedelta(months=+1))
# 后一个月
import datetime
import dateutil.relativedelta
NextBillDate = (datetime.datetime.strptime(Date, '%Y-%m-%d') + dateutil.relativedelta.relativedelta(months=1)).strftime("%Y-%m-%d")
# 两个日期间隔天数
import datetime
d1 = datetime.date(2015,10,7)
d2 = datetime.date(2015,8,15)
print((d1-d2).days)