将“##h ##m”转换为##.##小时
Converting "##h ##m" to ##.## hours
我的时间跟踪应用程序以下列格式导出员工工时:
xxh yym
我正在寻找一种方法将其转换为十进制小时数。例如,
input(06h 30m)
return(6.5)
无法找到在 Google 表格或 Excel 上执行此操作的方法。我尝试创建一个新功能,但这远远超出了我的能力范围。我的编码经验很少。
感谢您的帮助!
我不完全确定你所说的 "input" 是什么意思,也不确定它是否在你正在解析的单元格或某种数据源中,并且不清楚“06h 30m”是否描述是具有自定义格式的单元格中的时间值,或者它是文本字段。
此答案假定数据是一个文本字段(在单元格 A2 中)并且您希望 return 将数字表示为小时和小时的小数部分,最多为 24 小时(因为我也是假设这些是一天中的员工小时数)。它假定总是有两位数的小时数或分钟数,并且在 xxh 和 yym 之间有一个 space:
=TIME(LEFT(A2,2),MID(A2,5,2),0)*24
我希望这至少能引导您朝着您想要到达的方向前进。
Function ConvertTime(hours, minutes)
return hours + (minutes/60)
End Function
替代公式:
=24*TIMEVALUE(SUBSTITUTE(SUBSTITUTE(A1,"m",""),"h ",":"))
在 Google Sheets 上,您可以根据以下公式通过 REGEXEXTRACT()
内置函数执行此操作(假设您的文本存储在 A1
)
=REGEXEXTRACT(A1,"^(\d{2})h \d{2}m") + REGEXEXTRACT(A1,"^\d{2}h (\d{2})m")/60
REGEXEXTRACT()
is a regular expression extractor function. The input
text of 06h 30m
have the following pattern ^\d{2}h \d{2}m
where
^
refers to start of the string
\d
refers to single digit number, \d{2}
means two digits
h
, </code>, <code>m
are all characters as they appear in the reference text.
Hence, by using ()
around the portions we need to extract from the
text and simple arithmetic you can convert the 06h 30m
into 6.5
More information about regular expression syntax can be found in this
tutorial
我的时间跟踪应用程序以下列格式导出员工工时:
xxh yym
我正在寻找一种方法将其转换为十进制小时数。例如,
input(06h 30m)
return(6.5)
无法找到在 Google 表格或 Excel 上执行此操作的方法。我尝试创建一个新功能,但这远远超出了我的能力范围。我的编码经验很少。
感谢您的帮助!
我不完全确定你所说的 "input" 是什么意思,也不确定它是否在你正在解析的单元格或某种数据源中,并且不清楚“06h 30m”是否描述是具有自定义格式的单元格中的时间值,或者它是文本字段。
此答案假定数据是一个文本字段(在单元格 A2 中)并且您希望 return 将数字表示为小时和小时的小数部分,最多为 24 小时(因为我也是假设这些是一天中的员工小时数)。它假定总是有两位数的小时数或分钟数,并且在 xxh 和 yym 之间有一个 space:
=TIME(LEFT(A2,2),MID(A2,5,2),0)*24
我希望这至少能引导您朝着您想要到达的方向前进。
Function ConvertTime(hours, minutes)
return hours + (minutes/60)
End Function
替代公式:
=24*TIMEVALUE(SUBSTITUTE(SUBSTITUTE(A1,"m",""),"h ",":"))
在 Google Sheets 上,您可以根据以下公式通过 REGEXEXTRACT()
内置函数执行此操作(假设您的文本存储在 A1
)
=REGEXEXTRACT(A1,"^(\d{2})h \d{2}m") + REGEXEXTRACT(A1,"^\d{2}h (\d{2})m")/60
REGEXEXTRACT()
is a regular expression extractor function. The input text of06h 30m
have the following pattern^\d{2}h \d{2}m
where
^
refers to start of the string\d
refers to single digit number,\d{2}
means two digitsh
,</code>, <code>m
are all characters as they appear in the reference text.Hence, by using
()
around the portions we need to extract from the text and simple arithmetic you can convert the06h 30m
into6.5
More information about regular expression syntax can be found in this tutorial