【问题标题】:Datetime from strings with microseconds来自带有微秒的字符串的日期时间
【发布时间】:2013-10-10 07:22:31
【问题描述】:

如何在日期时间中包含微秒,例如:

import datetime

dt = datetime.datetime.strptime('2010-08-30 15:02:55.730', '%Y-%m-%d %H:%M:%S')

>>> ValueError: unconverted data remains: .730

我也想要微秒。格式字符串应该是什么样的?微秒的占位符是什么?

【问题讨论】:

  • .xxx 是毫秒。 .xxxxxx 是微秒。 (幸运的是,%f 两者都处理)

标签: python datetime python-2.7 time strptime


【解决方案1】:
dt = datetime.datetime.strptime('2010-08-30 15:02:55.730', '%Y-%m-%d %H:%M:%S.%f')

你可以看看:

http://docs.python.org/2/library/datetime.html#strftime-strptime-behavior

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 2021-01-06
    • 2022-11-23
    相关资源
    最近更新 更多