Skip to content

Instantly share code, notes, and snippets.

@suncle1993
Created December 13, 2017 07:35
Show Gist options
  • Save suncle1993/b1847ded921275b4ca259e111e56346b to your computer and use it in GitHub Desktop.
Save suncle1993/b1847ded921275b4ca259e111e56346b to your computer and use it in GitHub Desktop.
1、获取当天0点的时间戳 2、获取指定时间戳所在天0点的时间戳
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
import datetime
import os
import time
def getTimeOClockOfToday():
t = time.localtime(time.time())
time1 = time.mktime(time.strptime(time.strftime('%Y-%m-%d 00:00:00', t),'%Y-%m-%d %H:%M:%S'))
return int(time1)
def getTimeOClock(timestamp):
t = time.localtime(timestamp)
time1 = time.mktime(time.strptime(time.strftime('%Y-%m-%d 00:00:00', t),'%Y-%m-%d %H:%M:%S'))
return int(time1)
print(getTimeOClockOfToday())
print(1512445645- getTimeOClock(1512445645))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment