如下所示:
#!/usr/bin/python# coding=utf-8#import timeimport 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'))) - 1print '今天时间戳'print today_start_timeprint today_end_timeprint '昨天时间戳'print yesterday_start_timeprint yesterday_end_timeprint '明天时间戳'print tomorrow_start_timeprint tomorrow_end_time
输出结果
/usr/bin/python2.7 /home/he/dev/python_my/test.py今天时间戳14982336001498319999昨天时间戳14981472001498233599明天时间戳14983200001498406399Process finished with exit code 0
以上这篇Python获取昨天、今天、明天开始、结束时间戳的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林站长站。
新闻热点
疑难解答