【问题标题】:how to specify hourly time range in djagno?如何在 django 中指定每小时的时间范围?
【发布时间】:2022-07-08 00:58:19
【问题描述】:

我想在特定时间范围内接受订单,只是我想验证订单是否在 8:00-19:00 之间,无论是哪一天或哪一天。

【问题讨论】:

    标签: django django-rest-framework


    【解决方案1】:

    您可以使用 datetime 进行如下操作:

    def your_function(request):
        current_time = dt.now(tz=zoneinfo.ZoneInfo('UTC'))
        if 8 < current_time.hour < 19:
            # Accept the order and process accordingly
        else:
            # Don't accept and send different response
    

    【讨论】:

      猜你喜欢
      • 2022-12-03
      • 2012-08-26
      • 2021-10-01
      • 2019-05-27
      • 2012-04-02
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多