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

作者:偶爱喝可乐 时间:2022-08-23 18:23:40 

如下所示:


#!/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

来源:https://blog.csdn.net/qq_26656329/article/details/73658250

标签:Python,时间戳,昨天,今天,明天
0
投稿

猜你喜欢

  • IE6/7关于 Absolute Position 、relative 的一些意外

    2008-11-27 11:34:00
  • Jupyter notebook远程访问服务器的方法

    2022-12-25 22:04:36
  • python实现批量文件重命名

    2021-03-25 22:04:38
  • Go语言实现新春祝福二维码的生成

    2023-10-16 06:14:32
  • 比较SQL Server与Oracle、DB2三种数据库

    2008-09-12 17:24:00
  • 如何在网页设计中使用个性化字体

    2009-07-07 11:29:00
  • python urllib库的使用详解

    2021-06-12 14:42:04
  • 使用Python的toolz库开始函数式编程的方法

    2022-10-18 10:29:55
  • PHP实现ASCII码与字符串相互转换的方法

    2023-09-09 13:27:05
  • 详解python之多进程和进程池(Processing库)

    2022-07-18 23:23:58
  • Access数据库用另一种方式管理密码

    2008-10-13 12:25:00
  • Python爬虫爬取Bilibili弹幕过程解析

    2021-11-26 02:58:49
  • 深入浅析python 协程与go协程的区别

    2022-02-16 23:57:26
  • 在asp中使用js的encodeURIComponent方法

    2012-11-30 20:05:53
  • 用户界面设计中“状态”和“动作”的表达

    2011-01-06 12:36:00
  • Python 支持向量机分类器的实现

    2021-05-13 01:54:57
  • 使用Title提升可访问性二

    2009-11-16 12:53:00
  • W3C优质网页小贴士(四)

    2008-04-17 13:34:00
  • Windows下ORACLE 10g完全卸载的方法分析

    2012-07-11 16:09:26
  • win7 x64系统中安装Scrapy的方法

    2023-10-19 04:04:36
  • asp之家 网络编程 m.aspxhome.com