【问题标题】:RobotFramework: Date format conversion issueRobotFramework:日期格式转换问题
【发布时间】:2017-06-20 17:48:50
【问题描述】:

我不确定这里出了什么问题。我已经给出了转换的时间,时间的格式,以及结果的格式,像这样:

${date_to_search_for}=  Convert Date  2017-06-14 13:03:02.506610  date_format=%Y-%m-%d 00:00:00.00000  result_format=%d %b %Y 00:00:00  exclude_millis=True
Log to console  ${date_to_search_for}

运行此代码,出现此错误:

ValueError: time data '2017-06-14 13:03:02.506610' does not match format '%Y-%m-%d 00:00:00.00000'

我仔细检查了这两种格式,看不出有什么区别!我不明白为什么会抛出这个错误。

【问题讨论】:

    标签: robotframework date-format


    【解决方案1】:

    你给机器人的日期:

    2017-06-14 13:03:02.506610
    

    不是你说的格式

    date_format=%Y-%m-%d 00:00:00.00000
    

    请像这样使用 DateTime 的 Python 格式:

    ${date_to_search_for}=    Convert Date    2017-06-14 13:03:02.506610    date_format=%Y-%m-%d %H:%M:%S.%f     result_format=%d %b %Y 00:00:00    exclude_millis=True
    Log to console  ${date_to_search_for}
    

    请注意%H:%M:%S.%f 的时间要求。

    %H = 24 Hour Hour Time
    %M = Minute with leading 0
    %S = seconds with leading 0
    %f = microseconds with leading 0
    

    都可以找到Here

    这将导致以下格式被记录:

    ${date_to_search_for} = 14 Jun 2017 00:00:00
    

    有什么问题请追问:)

    【讨论】:

    • 啊,抱歉,金发女郎。在我的辩护中,还没有咖啡。谢谢
    • 没问题,伙计,发生在我们所有人身上! :D
    • 等待...仍然遇到一个问题 ValueError: time data '2017-06-14 13:03:02.506610' does not match format '%Y-%m-%d 00:00:00.000000 '
    • 让我帮你检查一下 - 我会在我的机器上设置机器人,给我几分钟,然后为你整理一下
    猜你喜欢
    • 2012-04-16
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 2013-08-21
    • 2016-10-08
    相关资源
    最近更新 更多