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
songkaiape
V2EX  ›  Python

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

  •  
  •   songkaiape · 2020-10-20 19:50:46 +08:00 · 1503 次点击
    这是一个创建于 1255 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2020-10-21 13:57:47 +08:00
    starzh
        1
    starzh  
       2020-10-21 08:25:20 +08:00
    是 milliseconds 不是 millisecondes,print 少了一个’)‘
    python 3.8.5
    我运行了一下没有问题,结果是’18721226225320‘
    user8341
        2
    user8341  
       2020-10-21 13:57:47 +08:00
    为什么要处理古代的日期
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4384 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:04 · PVG 09:04 · LAX 18:04 · JFK 21:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.