python - 时间戳 python 中昨天的开始和结束时间

标签 python linux unix-timestamp

我想获取昨天linux时间戳的开始时间和结束时间

import time
startDay = time.strftime('%Y-%m-%d 00:00:00')
print startDay
endDay   =time.strftime('%Y-%m-%d 23:59:59')
print endDay

Output is:

2016-11-18 00:00:00

2016-11-18 23:59:59

这在字符串中显示今天的开始时间和结束时间 我想在 linux 时间戳中获取昨天的开始时间和结束时间 喜欢:

4319395200

4319481599

最佳答案

import time
def datetime_timestamp(dt):
    time.strptime(dt, '%Y-%m-%d %H:%M:%S')
    s = time.mktime(time.strptime(dt, '%Y-%m-%d %H:%M:%S'))
    return int(s)

关于python - 时间戳 python 中昨天的开始和结束时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40672243/

相关文章:

linux - Linux 中文件大小增加的进度条

mysql - 如何将 1960 年代的日期插入 mysql 中的时间戳字段?

用于 tsv 平面文件的 python/bash SQL(无 sqlite)

python - python中的对数正态混合

Python:使用 openpyxl 模块的字体属性时出现 AttributeError

python - 从一堆 SQL 语句中解析表名

linux - 创建等于文件中行的变量,并按顺序为变量分配文件中的值

unix - UNIX 目录何时更改其时间戳

mysql - 从现在开始扣除较旧的日期()

python - 使用 sqlalchemy python 将 JSON 数据导入 SQL