- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在用 Python 开发一个项目(必须自学 Python,目前仍在学习),该项目从给我的 csv 文件中获取数据。
我目前对如何遍历列表以将列表中的字符串(例如“2 小时 5 分 15 秒”)转换为小数并将其保存为另一个列表/数组感到困惑。
我知道 H:M:S,但在列表的某些区域,它只是“8 分 4 秒”,因此它从有小时计数到只有分钟和秒不等。
最佳答案
函数:
def hms_to_mins(t):
h, m, s = [int(i) for i in t.split(' ')]
return float(60*h + m + (s/60))
hms_to_mins('5 30 0')
输出:330.0
您可以添加更多内容来验证输入并检查是否有 3 个输入(小时、分钟和秒)。
如果您想将输入作为“5hrs 30mins 2sec”并运行,在上面的代码中只需使用这个(而不是 hms_to_mins('5 30 0')
):
import re
t=' '.join(re.findall('\d+', s))
hms_to_mins(t)
所以代码应该是:
import re
def hms_to_mins(t):
h, m, s = [int(i) for i in t.split(' ')]
return float(60*h + m + (s/60))
s='5hrs3mins0sec' //your time string
t=(re.findall('\d+', s))
while(len(t)<3): t.append(str(0))
t=' '.join(t)
hms_to_mins(t)
输出:303.0
关于Python:将 "- hrs - min - sec' 字符串更改为分钟十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37474558/
我在 c# 中以这种方式将 Hour 转换为 12 HRS/24 HRS 格式,但无法在 javascript 中执行相同的操作。 我的 c# 代码用于格式化 12 HRS/24 HRS 格式如下 f
我正在编写一个查询,该查询选择两次并计算两次之间的差异,其中一个是开始,另一个是结束以找出持续时间。然而,两者在mysql中都设置为TIME类型。我如何格式化时间而不是将 HH:MM:SS 显示为 '
实际上我使用的是MySql 5.6.4版本。但问题是MySQL以“hh:mm:ss”格式(或“hhh:mm:ss”格式)检索并显示TIME值对于较大的小时值)。 TIME 值的范围可能是“-838:5
实际上我使用的是MySql 5.6.4版本。但问题是MySQL以“hh:mm:ss”格式(或“hhh:mm:ss”格式)检索并显示TIME值对于较大的小时值)。 TIME 值的范围可能是“-838:5
我目前正在用 Python 开发一个项目(必须自学 Python,目前仍在学习),该项目从给我的 csv 文件中获取数据。 我目前对如何遍历列表以将列表中的字符串(例如“2 小时 5 分 15 秒”)
我如何在 C# 中添加 (DateTime?) 和 (long?),其中 long 是 hrs。日期时间中的预期结果 最佳答案 DateTime dt = DateTime.Now;
我正在尝试让计时器显示以下内容 - 小时:分钟:秒:毫秒。我找到了一个介绍如何操作的网站教程,但没有显示时间。这是网站:Simple-stopwatch 这是它说要做的代码: var timer =
我是一名 C# 初学者。我正在用 MVP 编写 Web 应用程序,但无法将 12 小时制转换为 24 小时制。因此,有三个下拉框(小时、分钟、上午/下午)当 AM/PM 下拉列表显示为 PM 时,小时
Date Y 12/16/2013 7:00 104052 12/16/2013 15:00 103213 12/16/2013 23:00 104724 12/17/2013 7:
我的表有示例数据,我需要计算两列中两个时间戳之间的营业时间。营业时间:上午 9:00 至下午 5:00,忽略周六和周日,我不考虑公共(public)假期。有人可以提供一些关于如何实现这一目标的指导吗?
a) 所以我有一个巨大的 .csv 数据文件夹,其中有一个关于持续时间的列,其中单元格是“x min y sec”(例如 15 min 29 sec)或“x hrs y min z sec”(例如 1
我正在尝试使用 date-fns 库显示倒数计时器并按照以下方式执行操作,但无法在 react 中找到解决方案。 预期输出:60 天:8 小时:9 分钟:剩余 5 秒 const finish
我需要在每个 zip 中显示最高的 num_add 及其相关的 hrs 分数。 所以 hrs 在每个 zip 中有多个值和 num_add。 如何在每个 zip 中只显示最高的 num_add 及其
我正在使用highcharts 。我有一个分组的堆积条形图,其中包含两个系列的收入和小时数,以及计费/未计费的堆积系列。我想在条形图上显示缩写为 K/M 的小时标签,货币条形图也是如此(但数字前面有“
我需要一种方法来在 crontab 上创建一个在 24 小时内只执行一次脚本的条目。 步骤: 运行 bash 脚本以配置 crontab 以在 24 小时内运行脚本(使用命令 date?)。这将仅在
在我的程序中,我需要以特定格式(2015-11-18 12:23:00)提醒当前日期和时间,所以我这样写 var date = new Date(); alert(date
我在 MySQL 数据库中有一个表,它使用 UTC 时间戳注册特定用户的事件。我想创建一个新列,并将 2:30hrs 添加到记录的所有事件的时间中。该表有多列。 例如:- date
我是一名优秀的程序员,十分优秀!