V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
songkaiape
V2EX  ›  Python

Python 处理 1870 年 epoch time 之前的时间

  •  
  •   songkaiape · Oct 20, 2020 · 1964 views
    This topic created in 2026 days ago, the information mentioned may be changed or developed.

    VMS 时间戳默认时间是 1858 年 11 月 17 日,需要转换为正常的时间戳,如果直接使用 time 读取 18581117 再加上毫秒然后进行转换会导致溢出。百度了一下没找到类似问题解答,所以在 V2 记录一下方便后来遇到类似问题的人。 可以使用 timedelta 就可以避免溢出的问题

    import datetime
    start_date=datetime.datetime.strptime('18581117','%Y%m%d')
    vms_timestamp=4453016000000000
    date=start_date+datetime.timedelta(millisecondes=vms_timestamp/10000)
    print(date.strftime('%Y%m%d%H%M%S')
    
    2 replies    2020-10-21 13:57:47 +08:00
    starzh
        1
    starzh  
       Oct 21, 2020
    是 milliseconds 不是 millisecondes,print 少了一个’)‘
    python 3.8.5
    我运行了一下没有问题,结果是’18721226225320‘
    9LCRwvU14033RHJo
        2
    9LCRwvU14033RHJo  
       Oct 21, 2020
    为什么要处理古代的日期
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1087 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 23:02 · PVG 07:02 · LAX 16:02 · JFK 19:02
    ♥ Do have faith in what you're doing.