Python獲取昨天、今天、明天開始、結束時間戳
import datetime
tmp = (datetime.date.today() - datetime.timedelta(days=6)).strftime("%Y%m%d_%H%M%S")
print(tmp)
#!/usr/bin/python
# coding=utf-8
#
import time
import datetime
# 今天日期
today = datetime.date.today()
# 昨天時間
yesterday = today - datetime.timedelta(days=1)
# 明天時間
tomorrow = today + datetime.timedelta(days=1)
acquire = today + datetime.timedelta(days=2)
# 昨天開始時間戳
yesterday_start_time = int(time.mktime(time.strptime(str(yesterday), '%Y-%m-%d')))
# 昨天結束時間戳
yesterday_end_time = int(time.mktime(time.strptime(str(today), '%Y-%m-%d'))) - 1
# 今天開始時間戳
today_start_time = yesterday_end_time + 1
# 今天結束時間戳
today_end_time = int(time.mktime(time.strptime(str(tomorrow), '%Y-%m-%d'))) - 1
# 明天開始時間戳
tomorrow_start_time = int(time.mktime(time.strptime(str(tomorrow), '%Y-%m-%d')))
# 明天結束時間戳
tomorrow_end_time = int(time.mktime(time.strptime(str(acquire), '%Y-%m-%d'))) - 1
print '今天時間戳'
print today_start_time
print today_end_time
print '昨天時間戳'
print yesterday_start_time
print yesterday_end_time
print '明天時間戳'
print tomorrow_start_time
print tomorrow_end_time