Python实现根据日期获取当天凌晨时间戳的方法示例
Python  /  管理员 发布于 8年前   284
本文实例讲述了Python实现根据日期获取当天凌晨时间戳的方法。分享给大家供大家参考,具体如下:
# -*- coding:utf-8 -*-#! python2'''Created on 2019年4月9日@author: Administrator'''import datetimeimport timedef get_day_zero_time(date): """根据日期获取当天凌晨时间""" if not date: return 0 date_zero = datetime.datetime.now().replace(year=date.year, month=date.month, day=date.day, hour=0, minute=0, second=0) date_zero_time = int(time.mktime(date_zero.timetuple())) return date_zero_time# 今天的日期today_date = datetime.datetime.now().date()# 今天的零点today_zero_time = get_day_zero_time(today_date)#print today_dateprint today_zero_time
运行结果:
1554739200
PS:这里再为大家推荐几款关于日期与天数计算的在线工具供大家使用:
在线日期/天数计算器:
http://tools..net.cn/jisuanqi/date_jisuanqi
在线万年历日历:
http://tools..net.cn/bianmin/wannianli
在线阴历/阳历转换工具:
http://tools..net.cn/bianmin/yinli2yangli
Unix时间戳(timestamp)转换工具:
http://tools..net.cn/code/unixtime
更多关于Python相关内容感兴趣的读者可查看本站专题:《Python日期与时间操作技巧总结》、《Python数学运算技巧总结》、《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》
希望本文所述对大家Python程序设计有所帮助。
test1 在
opencode + Oh-my-openagent,我的第一个免费的ai编程智能体管家:Sisyphus中评论 test..122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..Zita 在
Google AI Studio升级全栈 vibe coding体验,可直接构建带登录和数据库的应用中评论 111222..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
