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

求助 Python 有什么库可以快捷的转换时间到类似 ISODate"2018-06-21T07:57:04.229Z"这样的格式

  •  
  •   datou · 2018-07-10 15:30:04 +08:00 · 3662 次点击
    这是一个创建于 2109 天前的主题,其中的信息可能已经有所发展或是发生改变。
    2 条回复    2018-07-10 15:59:04 +08:00
    NobodyVe2x
        1
    NobodyVe2x  
       2018-07-10 15:36:02 +08:00
    参考:
    #'Thu Mar 31 17:31:45 CST 2016' => 20160331173145
    def convertdatastring(dstr):
    timestamp = time.mktime(time.strptime(dstr, '%a %b %d %H:%M:%S CST %Y'))
    result = datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y%m%d%H%M%S')
    return result

    如果是反过来,直接 format 格式化啊!
    welkinzh
        2
    welkinzh  
       2018-07-10 15:59:04 +08:00
    datetime.datetime.now().isoformat()
    是这样吗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5262 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 01:25 · PVG 09:25 · LAX 18:25 · JFK 21:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.