我收到了代表军事时间的自定义格式(类型:000000)的数字列表。它始终包含 6 位数字,必要时使用前导零。例如:
如何将 A 列中的整数转换为 B 列中的格式 (hh:mm:ss)?我想使用军用 24 小时制时钟。
最佳答案
假设它是一个实整数,而不是文本:=TIME(INT(A1/10000),INT(MOD(A1,10000)/100),MOD(A1,100))
如果是文本,则使用=TIME(VALUE(LEFT(A1,2)),VALUE(MID(A1,3,2)),VALUE(RIGHT(A1,2)))
根据需要格式化结果。
作为 VBA 函数: 整数:
Function RetTime(IntTime As Long) As Date
RetTime = TimeSerial(Int(IntTime / 10000), Int((IntTime Mod 10000) / 100), (IntTime Mod 100))
End Function
字符串:
Function RetTimeS(StrTime As String) As Date
RetTimeS = TimeSerial(Val(Left(StrTime, 2)), Val(Mid(StrTime, 3, 2)), Val(Right(StrTime, 2)))
End Function
关于excel - 如何将给定数字转换为时间格式 HH :MM:SS in VBA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11087787/