Python实现根据日期获取当天凌晨时间戳的方法示例

就让心静静地置于时光的一隅,用一片花香的暖,守候心灵的风景,正如世间每一种长久的缘都要悉心来呵护。经年后,那久久留存在心底的目光,是微细的心,是相知的暖。一梦许是无痕,一梦花又盛开。年复一年,碾过昔日的足迹,我的灵魂睡在那些温暖的文字里,与感恩和快乐相依,或喜或泣,皆是生活的一脉馨香。 "

本文实例讲述了Python实现根据日期获取当天凌晨时间戳的方法。分享给大家供大家参考,具体如下:

# -*- coding:utf-8 -*-
#! python2
'''
Created on 2019年4月9日
@author: Administrator
'''
import datetime
import time
def 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_date
print today_zero_time

运行结果:

1554739200

PS:这里再为大家推荐几款关于日期与天数计算的在线工具供大家使用:

在线日期/天数计算器:
http://tools.haodaima.com/jisuanqi/date_jisuanqi

在线万年历日历:
http://tools.haodaima.com/bianmin/wannianli

在线阴历/阳历转换工具:
http://tools.haodaima.com/bianmin/yinli2yangli

Unix时间戳(timestamp)转换工具:
http://tools.haodaima.com/code/unixtime

希望本文所述对大家Python程序设计有所帮助。

本文Python实现根据日期获取当天凌晨时间戳的方法示例到此结束。努力在黑暗中站上舞台,是想成为万人的光。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
Python自动化运维-使用Python脚本监控华为AR路由器关键路由变化

Python自动化运维-netmiko模块设备自动发现

Python自动化运维—netmiko模块连接并配置华为交换机

Python自动化运维-利用Python-netmiko模块备份设备配置

Python自动化运维-Paramiko模块和堡垒机实战