如何从python中的日期时间字符串中删除秒和毫秒 [英] How do you remove seconds and milliseconds from a date time string in python

查看:1063
本文介绍了如何从python中的日期时间字符串中删除秒和毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How I can convert a date in format "2013-03-15 05:14:51.327" to "2013-03-15 05:14", i.e. removing the seconds and milliseconds. I don't think there is way in Robot frame work. Please let me know if any one have a solution for this in python.

推荐答案

尝试一下(感谢Blender!)

Try this (Thanks Blender!)

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

这篇关于如何从python中的日期时间字符串中删除秒和毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆