首页 > 解决方案 > String time convert to only timestamp using python

问题描述

I have a time 00:11:21.600000 like this in each row of excel I want to convert to time stamp in hrs and mins

标签: python-3.x

解决方案


You can use the inbuilt datetime module:

from datetime import datetime


your_time = datetime.strptime('00:11:21.600000', '%H:%M:%S.%f')

Then you have a datetime object your_time on which you can perform different actions, for example:

Get str with hours and minutes: your_time.strftime('%H:%M')

For more methods see the docs here.


推荐阅读