V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
martyartrt1
V2EX  ›  Python

Python web.py 时间日期会加速。为什么哪里错了。要怎么改?

  •  
  •   martyartrt1 · 2018-11-09 11:49:43 +08:00 · 1753 次点击
    这是一个创建于 1966 天前的主题,其中的信息可能已经有所发展或是发生改变。
    class Web_time():
    tz = pytz.timezone('Pacific/Auckland')
    now = datetime.datetime.now(tz) # 今天
    today = now.strftime('%Y-%m-%d %H:%M:%S')
    yesterday = now - timedelta(days=1) # 昨天
    day3 = (now - timedelta(days=3)).strftime('%Y-%m-%d %H:%M:%S') # 三天前
    day30 = (now - timedelta(days=30)).strftime('%Y-%m-%d %H:%M:%S') # 31 天前
    tomorrow = (now + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S') # 明天
    this_month_start = datetime.datetime(now.year, now.month, 1) # 本月第一天和最后一天
    this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1)
    # 上月第一天和最后一天
    last_month_end = this_month_start - timedelta(days=1)
    last_month_start = datetime.datetime(last_month_end.year, last_month_end.month, 1)

    这个类,用在 web.py 下面,去调用里面的参数。web.py 刚开始运行 显示的时间是对的。
    但是 web.py 运行一两天以后时间 就会加速。比正常时间快。这种是什么情况
    第 1 条附言  ·  2018-11-09 13:32:39 +08:00
    刚才看一个生成的数。时间被减速了。
    第 2 条附言  ·  2018-11-09 14:03:11 +08:00
    已经解决。 是类中参数被静态化了。
    把参数改成方法调用 就 Ok。
    4 条回复    2018-11-16 11:50:31 +08:00
    Belmode
        1
    Belmode  
       2018-11-09 13:28:56 +08:00
    会不会是精度不够
    martyartrt1
        2
    martyartrt1  
    OP
       2018-11-09 13:32:09 +08:00
    @Belmode 不是吧,我现在在想 是不是类里面的值变成静态的。
    时间被减速了。
    lufangfan
        3
    lufangfan  
       2018-11-16 11:00:58 +08:00
    你如果感觉时间比正常时间快,是由于你所处的位置引力场太强导致的。
    martyartrt1
        4
    martyartrt1  
    OP
       2018-11-16 11:50:31 +08:00
    @lufangfan 感谢好有深度的回答
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2997 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 14:58 · PVG 22:58 · LAX 07:58 · JFK 10:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.