加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python获取昨天、今天、明天开始、结束时间戳的方法

发布时间:2020-12-20 10:20:26 所属栏目: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 +
#!/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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读