How do you remove seconds and milliseconds from a date time string in python

泪湿孤枕 提交于 2019-12-01 17:53:37

Try this (Thanks Blender!)

>>> date = "2013-03-15 05:14:51.327"
>>> newdate = date.rpartition(':')[0]
>>> print newdate
2013-03-15 05:14

In Robotframework the most straightforward way would be to user Split String From Right from the String library library:

${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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!