Python获取昨天、今天、明天开始、结束时间戳的方法
如下所示:
#!/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
输出结果
/usr/bin/python2.7 /home/he/dev/python_my/test.py 今天时间戳 1498233600 1498319999 昨天时间戳 1498147200 1498233599 明天时间戳 1498320000 1498406399 Process finished with exit code 0
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16