国外日期格式转为国内格式
# -*- coding: utf-8 -*-
import datetime
import time
from dateutil.relativedelta import relativedelta
import pandas as pd
i = '08 Apr 2019 - 12:55 pm'
def to_datetimes(i):
ti = pd.to_datetime(i, errors='ignore')
t_strf = str(ti)[:10]
return t_strf # 2019-04-08
# pandas时间戳转日期
pd.to_datetime(pt, unit='s', origin=pd.Timestamp('1970-01-01 08:00:00'))
毫秒时间戳
one = int(round(time.time()*1000))
print(one) # 1554581871092
时间戳 + 30天
two = int(round(time.time()+2592000))
print(two) # 1557173871
时间戳转为格式化时间2019-05-04 16:32:14
three = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1556958734.538386))
print(three) # 2019-05-04 16:32:14
four = datetime.date.today()
print(four) # 2019-04-07
# 避免2月没30号报错
print(datetime.date.today() - relativedelta(years=-1) - relativedelta(days=+1)) # 2020-04-06
#mysql删除三天之后的数据
mysql删除三天之后的数据
delete from '表' where datediff(curdate(), '日期字段')>=3