Python获取自然月时间并转换时间戳

2019-08-23  本文已影响0人  别谈以后Axy
import os,sys
import MySQLdb
import datetime
import time
reload(sys)
sys.setdefaultencoding('utf8')

def getMonth():
       year = str(datetime.date.today().year)
       d = datetime.date.today()
       month = '%02d' % d.month
       if month in ['01','03','05','07','08','10','12']:
               s = str("-01 00:00:00")
               e = str("-31 23:59:59")
               startTime = year + "-" + str(month) + s
               endTime = year + "-" +  str(month) + e
               list = [startTime,endTime]
               return list
       elif month == '02':
               s = str("-01 00:00:00")
               e = str("-28 23:59:59")
               startTime = year + "-" + str(month) + s
               endTime = year + "-" +  str(month) + e
               list = [startTime,endTime]
               return list
       else:
               s = str("-01 00:00:00")
               e = str("-30 23:59:59")
               startTime = year + "-" + str(month) +s
               endTime = year + "-" +  str(month) + e
               list = [startTime,endTime]
               return list
list_time = getMonth()
starTimestamp = int(time.mktime(time.strptime(list_time[0], '%Y-%m-%d %H:%M:%S')))
endTimestamp = int(time.mktime(time.strptime(list_time[1], '%Y-%m-%d %H:%M:%S')))
[root@mailvip python]# py recording.py
1564588800
1567180799
[root@mailvip python]#
上一篇下一篇

猜你喜欢

热点阅读