Generating 15 minute time interval array in python
<p>I am new to python. I am trying to generate time interval array. for example:
<code>
time_array = 
["2016-09-02T17:30:00Z", "2016-09-02T17:45:00Z", "2016-09-02T18:00:00Z", "2016-09-02T18:15:00Z", "2016-09-02T18:30:00Z", "2016-09-02T18:45:00Z"]
</code>
1. It should create the element like above in zulu time till 9 pm everyday.
2. Should generate the elements for next and day after next as well
3. Start time from 7:00 am - Ed time 9:00 pm,
if current_time is > start_time then generate 15 min time interval array till 9 pm. and then generate for next day and day + 2.
And Interval should be 7:00, 7:15 like that.. not in 7:12, 8:32</p>

<p>This is the final script I have written based on the answers posted on my question:</p>

<pre><code>from datetime import datetime
from datetime import timedelta
import calendar

current_utc = datetime.utcnow().strftime("%Y-%m-%d-%H-%M-%S")

current_year = int(current_utc.split("-")[0])
current_month = int(current_utc.split("-")[1])
current_date = int(current_utc.split("-")[2])
current_hour = int(current_utc.split("-")[3])
current_min = int(current_utc.split("-")[4])
current_sec = int(current_utc.split("-")[5])

#### To make minutes round to quarter ####
min_range_1 = range(1,16)
min_range_2 = range(16,31)
min_range_3 = range(31,46)
min_range_4 = range(46,60)

if current_min in min_range_1:
    current_min = 15
elif current_min in min_range_2:
    current_min = 30
elif current_min in min_range_3:
    current_min = 45
elif current_min in min_range_4:
    current_hour = current_hour + 1
    current_min = 0
else:
    print("Please check current minute.")

current_sec = 00

date_range_31 = range(1,32)
date_range_30 = range(1,31)

month_days_31 = [1,3,5,7,8,10,12]
month_days_30 = [4,6,9,11]

if current_month in month_days_31:
    if current_date == 31:
        next_day_month = current_month + 1
        next_day_date = 1
    else:
        next_day_month = current_month
        next_day_date = current_date
elif current_month == 2:
    if calendar.isleap(current_year):
        if current_date == 29:
            next_day_month = current_month + 1
            next_day_date = 1
        else:
            next_day_month = current_month
            next_day_date = current_date
    else:
        if current_date == 28:
            next_day_month = current_month + 1
            next_day_date = 1
        else:
            next_day_month = current_month
            next_day_date = current_date
elif current_month in month_days_30:
    if current_date == 30:
        next_day_month = current_month + 1
        next_day_date = 1
    else:
        next_day_month = current_month
        next_day_date = current_date
else:
    print("Please check the current month and date to procedd further.")

if current_hour &lt; 11:
    current_hour = 11
    current_min = 15
    next_day_date = current_date + 1

current_start = datetime(current_year,current_month,current_date,current_hour,current_min,current_sec)
current_end = datetime(current_year,current_month,current_date,21,15,0)

next_day_start = datetime(current_year,next_day_month,next_day_date,11,15,0)
next_day_end = datetime(current_year,next_day_month,next_day_date,21,15,0)

current_seconds = (current_end - current_start).total_seconds()
next_day_seconds = (next_day_end - next_day_start).total_seconds()

step = timedelta(minutes=15)

current_day_array = []
next_day_array = []

for i in range(0, int(current_seconds), int(step.total_seconds())):
    current_day_array.append(current_start + timedelta(seconds=i))

for i in range(0, int(next_day_seconds), int(step.total_seconds())):
    current_day_array.append(next_day_start + timedelta(seconds=i))

current_day_array = [i.strftime('%Y-%m-%dT%H:%M%:%SZ') for i in current_day_array]

print current_day_array
</code></pre>

<p>Which produces the following output:</p>

<pre><code>['2016-09-03T11:15:00Z', '2016-09-03T11:30:00Z', '2016-09-03T11:45:00Z', '2016-09-03T12:00:00Z', '2016-09-03T12:15:00Z', '2016-09-03T12:30:00Z', '2016-09-03T12:45:00Z', '2016-09-03T13:00:00Z', '2016-09-03T13:15:00Z', '2016-09-03T13:30:00Z', '2016-09-03T13:45:00Z', '2016-09-03T14:00:00Z', '2016-09-03T14:15:00Z', '2016-09-03T14:30:00Z', '2016-09-03T14:45:00Z', '2016-09-03T15:00:00Z', '2016-09-03T15:15:00Z', '2016-09-03T15:30:00Z', '2016-09-03T15:45:00Z', '2016-09-03T16:00:00Z', '2016-09-03T16:15:00Z', '2016-09-03T16:30:00Z', '2016-09-03T16:45:00Z', '2016-09-03T17:00:00Z', '2016-09-03T17:15:00Z', '2016-09-03T17:30:00Z', '2016-09-03T17:45:00Z', '2016-09-03T18:00:00Z', '2016-09-03T18:15:00Z', '2016-09-03T18:30:00Z', '2016-09-03T18:45:00Z', '2016-09-03T19:00:00Z', '2016-09-03T19:15:00Z', '2016-09-03T19:30:00Z', '2016-09-03T19:45:00Z', '2016-09-03T20:00:00Z', '2016-09-03T20:15:00Z', '2016-09-03T20:30:00Z', '2016-09-03T20:45:00Z', '2016-09-03T21:00:00Z', '2016-09-04T11:15:00Z', '2016-09-04T11:30:00Z', '2016-09-04T11:45:00Z', '2016-09-04T12:00:00Z', '2016-09-04T12:15:00Z', '2016-09-04T12:30:00Z', '2016-09-04T12:45:00Z', '2016-09-04T13:00:00Z', '2016-09-04T13:15:00Z', '2016-09-04T13:30:00Z', '2016-09-04T13:45:00Z', '2016-09-04T14:00:00Z', '2016-09-04T14:15:00Z', '2016-09-04T14:30:00Z', '2016-09-04T14:45:00Z', '2016-09-04T15:00:00Z', '2016-09-04T15:15:00Z', '2016-09-04T15:30:00Z', '2016-09-04T15:45:00Z', '2016-09-04T16:00:00Z', '2016-09-04T16:15:00Z', '2016-09-04T16:30:00Z', '2016-09-04T16:45:00Z', '2016-09-04T17:00:00Z', '2016-09-04T17:15:00Z', '2016-09-04T17:30:00Z', '2016-09-04T17:45:00Z', '2016-09-04T18:00:00Z', '2016-09-04T18:15:00Z', '2016-09-04T18:30:00Z', '2016-09-04T18:45:00Z', '2016-09-04T19:00:00Z', '2016-09-04T19:15:00Z', '2016-09-04T19:30:00Z', '2016-09-04T19:45:00Z', '2016-09-04T20:00:00Z', '2016-09-04T20:15:00Z', '2016-09-04T20:30:00Z', '2016-09-04T20:45:00Z', '2016-09-04T21:00:00Z']
</code></pre>

python arrays python-2.7