python 获取当天凌晨零点的时间戳方法

yipeiwu_com6年前Python基础

最近写python,遇到了一个问题,需要获取当日凌晨零点的时间戳,网上实在没有找到,自己手写了一个,有点挫

# -*- coding:utf-8 -*- 
import time 
 
now_time = int(time.time()) 
day_time = now_time - now_time % 86400 + time.timezone 
day_time_str = time.asctime(time.localtime(day_time)) 
print day_time 
print day_time_str 
 
import datetime 
today = datetime.date.today() 
today_time = int(time.mktime(today.timetuple())) 
print today_time 

输出如下:

1518105600

Fri Feb 9 00:00:00 2018

1518105600

以上这篇python 获取当天凌晨零点的时间戳方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python的Django框架下管理站点的基本方法

对于某一类网站, 管理界面 是基础设施中非常重要的一部分。 这是以网页和有限的可信任管理者为基础的界面,它可以让你添加,编辑和删除网站内容。 一些常见的例子: 你可以用这个界面发布博客,...

Python IDLE 错误:IDLE''s subprocess didn''t make connection 的解决方案

Python IDLE 错误描述: Subprocess Startup Error IDLE's subprocess didn't make connection. Eithe...

shell命令行,一键创建 python 模板文件脚本方法

写 python 文件时,每个文件开头都必须注明版本和编码。每次我 touch 文件之后粘贴这两句话让我不胜其烦。 由于我没有安装 python 的 IDE 工具,也没有为 vim 安装...

使用Python3内置文档高效学习以及官方中文文档

概述 从前面的对Python基础知识方法介绍中,我们几乎是围绕Python内置方法进行探索实践,比如字符串、列表、字典等数据结构的内置方法,和大量内置的标准库,诸如functools、...

pandas 把数据写入txt文件每行固定写入一定数量的值方法

pandas 把数据写入txt文件每行固定写入一定数量的值方法

我遇到的情况是:把数据按一定的时间段提出。比如提出每天6:00-8:00的每个数据,可以这样做: # -*-coding: utf-8 -*- import pandas as pd...