Get the time in 30 minutes after the current time, such as 11:30, 12:00 (and only data from 9:00 to 21:30 can be selected)

def get_timeslot():
    nowtime_str = time.strftime('%Y_%m_%d %H:%M', time.localtime())

    nowtime_num = time.time()

    get_min = nowtime_str.split(':')[-1]
    nowdate = nowtime_str.split(' ')[0]
    now_hour = nowtime_str.split(' ')[1].split(':')[0]

    get_min = int(get_min)
    goaltime_str = nowdate + ' ' + now_hour + ':30'
goaltime_num = time.mktime(time.strptime(goaltime_str,'%Y_%m_%d %H:%M'))
    


    if get_min < 30:
       starttime = goaltime_num
       print starttime
    else:
        starttime = goaltime_num + 1800
print starttime        
    time_slot = [starttime]
    for i in range(10):
        starttime = starttime+1800
        starttime_str = time.strftime('%Y_%m_%d %H:%M',time.localtime(starttime))
        print starttime_str
        hour = int(starttime_str.split(' ')[1].split(':')[0])
        min = int (starttime_str.split ( '' ) [ 1 ] .split ( ':' ) [ 0 ])
        now_total_min = hour*60+min
      #Determine whether the time is between 9:00-21:30
         if   now_total_min>= 540 and now_total_min <= 1290 :
            time_slot.append(starttime)
    print time_slot


get_timeslot()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325841936&siteId=291194637
Recommended