python-3.x - 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
解决方案
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.
推荐阅读
- google-bigquery - BigQuery 选择语句别名在 where 子句中不起作用
- android - 对话占据整个屏幕
- environment-variables - 局部变量实现
- r - Apache Lounge 服务器没有响应 Windows 机器上的 rpy2 包
- angularjs - facebook登录没有收到响应,没有显示错误
- cmake - CMake ExternalProject_Add 每次都会重建
- java - 如何在rest api post方法中获取实体作为参数?
- spring - 春季启动:路径参数为空
- php - 使用“list”函数时的PHP未定义偏移量消息
- vuetify.js - 数据表填充的项目不如预期