我正在尝试生成时间间隔数组。例如:

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"]
  • 它应该在祖鲁时间直到每天晚上9点之前创建上述元素。
  • 应该为next和next之后的第二天以及
  • 生成元素
  • 开始时间从7:00 am-Ed time 9:00 pm,
    如果current_time> start_time,则生成15分钟的时间间隔数组,直到9 pm。然后为第二天和第二天生成。
    间隔应该是这样的7:00,7:15 ..不在7:12,8:32
  • 最佳答案

    这是供您使用的通用datetime_range

    代码

    from datetime import datetime, timedelta
    
    def datetime_range(start, end, delta):
        current = start
        while current < end:
            yield current
            current += delta
    
    dts = [dt.strftime('%Y-%m-%d T%H:%M Z') for dt in
           datetime_range(datetime(2016, 9, 1, 7), datetime(2016, 9, 1, 9+12),
           timedelta(minutes=15))]
    
    print(dts)
    

    输出

    关于python - 在python中生成15分钟的时间间隔数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39298054/

    10-11 23:20
    查看更多