推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
Ne
V2EX  ›  Python

新人小白请问各位大佬,在 data 中的日期变量,应该怎样写才对 ?

  •  
  •   Ne · Aug 24, 2022 · 3057 views
    This topic created in 1503 days ago, the information mentioned may be changed or developed.
    import datetime

    now_time = datetime.datetime.now()
    yesterday = now_time + datetime.timedelta(days = -1)
    begin_time = yesterday.strftime('%Y-%m-%d 08:00:00')
    end_time = now_time.strftime('%Y-%m-%d 07:59:59')

    data = {
    'inTimeStart': '2022-08-18 08:00:00', # 开始时间
    'inTimeEnd': '2022-08-19 07:59:59', # 结束时间

    上面的运行正常


    下面这样的会出错

    data = {
    'inTimeStart': 'begin_time', # 开始时间
    'inTimeEnd': 'end_time', # 结束时间
    2 replies  •  2022-08-24 21:16:46 +08:00
    eason1874
        1
    eason1874  
       Aug 24, 2022   ❤️ 1
    后面是变量吧,把引号去掉,像这样

    'inTimeStart': begin_time,
    'inTimeEnd': end_time
    Ne
        2
    Ne  
    OP
       Aug 24, 2022
    @eason1874 感谢你!,按你说这样做可以。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2389 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:08 · PVG 16:08 · LAX 01:08 · JFK 04:08
    ♥ Do have faith in what you're doing.