python 蟒蛇获取时间区间

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 蟒蛇获取时间区间相关的知识,希望对你有一定的参考价值。

# coding:utf-8
# 经常需要获取时间区间就封装一下
import time
class dateData:
    def __init__(self,year,month,day):
        self.year = year
        self.month = month
        self.day = day
    def getYear(self):
        return str(self.year).zfill(4)
    def getMonth(self):
        return str(self.month).zfill(2)
    def getDay(self):
        return str(self.day).zfill(2)
    
def execute(start_date,end_date):
    timezone = 60*60*8  #8个小时时差
    dayLength = 60*60*24
    dateDataArr = []

    #start
    s_year = start_date[0:4]
    s_month = start_date[4:6]
    s_day = start_date[6:8]
    #end
    e_year = end_date[0:4]
    e_month = end_date[4:6]
    e_day = end_date[6:8]
	
    start_stamp = int(time.mktime(time.strptime('%s-%s-%s'%(s_year,s_month,s_day), '%Y-%m-%d')))+timezone
    end_stamp = int(time.mktime(time.strptime('%s-%s-%s'%(e_year,e_month,e_day), '%Y-%m-%d')))+timezone
    for i in range(start_stamp,end_stamp+dayLength,dayLength):
        date = time.gmtime(i)
        dateDataArr.append(dateData(date.tm_year,date.tm_mon,date.tm_mday))
    return dateDataArr
if __name__ == '__main__':
    data = execute('20180101','20180802')
    print(233)

以上是关于python 蟒蛇获取时间区间的主要内容,如果未能解决你的问题,请参考以下文章

python 蟒蛇从命令行中获取参数

python 蟒蛇获取正文

蟒蛇:MYSQLdb。如何在不执行 select * 在大表中获取列名?

整数的最后2位?蟒蛇 3

用python怎么把蟒蛇变成彩色?

如何用python绘制彩色蟒蛇