Generating 15 minute time interval array in python

前端 未结 6 1572
悲&欢浪女
悲&欢浪女 2020-12-08 10:15

I am trying to generate time interval array. for example:

time_array = [\"2016-09-02T17:30:00Z\", \"2016-09-02T17:45:00Z\", 
              \"2016-09-02T18:00         


        
6条回答
  •  佛祖请我去吃肉
    2020-12-08 11:09

    Looking at the data file, you should use the built in python date-time objects. followed by strftime to format your dates.

    Broadly you can modify the code below to however many date-times you would like First create a starting date.

    Today= datetime.datetime.today()
    

    Replace 100 with whatever number of time intervals you want.

    date_list = [Today + datetime.timedelta(minutes=15*x) for x in range(0, 100)]
    

    Finally, format the list in the way that you would like, using code like that below.

    datetext=[x.strftime('%Y-%m-%d T%H:%M Z') for x in date_list]
    

提交回复
热议问题