VBA双倍时间

VBA Double to Time

我有一个 VBA 用户表单,当我在输入数据后按保存时,它会写入一个跨页 sheet 并将我的时间和日期设置为正在写入跨页的 Now() sheet 我将 now() 值拆分为时间和日期,当我读回它时,我得到了日期,但我的时间是十进制格式我想将该十进制数转换回时间那是什么公式提前谢谢你我的十进制数字是类似于'0.12425576899'到目前为止我找到了这个但是它将它转换为'00:double:00'上的分钟这是代码

Public Function FromDecimalTime(ByVal t As Double) As Date
FromDecimalTime = TimeSerial(0, Fix(t), (t - Fix(t)) * 60)
End Function

下面将Double转换成Date格式。为了只显示日期格式的时间部分,使用Format函数:

Sub trythis()
Dim t As Double
t = Now()
Debug.Print CDate(t)
Debug.Print Format(t, "hh:mm:ss")

End Sub