获取6个月前首日的时间戳

获取6个月前首日的时间戳

  • 先获取月份
  • 在获取首日
  • 再转换为时间戳
import time,datetime
from dateutil.relativedelta import relativedelta
time.mktime(time.strptime((datetime.today() + relativedelta(months=-5)) \
	.strftime('%Y-%m-01 00:00:00'),"%Y-%m-%d %H:%M:%S"))
time.mktime((datetime.today() + relativedelta(months=-5)) \
	.replace(day=1,hour=0,minute=0,second=0).timetuple())

效率对比

获取6个月前首日的时间戳_第1张图片

你可能感兴趣的:(Python,Pythonic,Tips)