5

如何将日期格式转换"2013-03-15 05:14:51.327""2013-03-15 05:14",即删除秒和毫秒。我认为机器人框架工作没有办法。请让我知道是否有人在python中有解决方案。

4

2 回答 2

5

试试这个(感谢搅拌机!)

>>> date = "2013-03-15 05:14:51.327"
>>> newdate = date.rpartition(':')[0]
>>> print newdate
2013-03-15 05:14
于 2013-03-15T09:50:04.880 回答
0

在 Robotframework 中,最直接的方法是Split String From Right从 String 库库中获取用户:

${datestring}=    Set Variable    2019-03-15 05:14:51.327
${parts}=  Split String From Right    ${datestring}    :    max_split=1
# parts is a list of two elements - everything before the last ":", and everything after it
# take the 1st element, it is what we're after
${no seconds}=    Get From List     ${parts}    0
Log    ${no senods}    # 2019-03-15 05:14
于 2018-12-02T17:00:56.107 回答