2015-03-08 108 views
1

所以我試圖將我的一些項目從excel vba轉換爲vb。 但是,在轉換日期和時間戳時我遇到了困難。輸出時間格式爲「hh:mm:ss」vb

所以:我有一個秒數,即:3878,我想在vb顯示爲"hh:mm:ss"。在VBA我會使用函數.Format(time,"HH:MM:SS"),但是這似乎不起作用。

任何幫助,將不勝感激。

感謝 菲利普

回答

1

你可以嘗試這樣的事情:

intTotalSecs = 3878 
MsgBox intTotalSecs & "(s) ===> " & ConvertTime(intTotalSecs),vbinformation,"output time format as hh:mm:ss" 
'************************************************************ 
Function ConvertTime(intTotalSecs) 
Dim intHours,intMinutes,intSeconds,Time 
intHours = intTotalSecs \ 3600 
intMinutes = (intTotalSecs Mod 3600) \ 60 
intSeconds = intTotalSecs Mod 60 
If intHours = 0 Then intHours = "0"&intHours 
If intMinutes = 0 Then intMinutes = "0"&intMinutes 
If intSeconds = 0 Then intSeconds = "0"&intSeconds 
ConvertTime = LPad(intHours) & " h : " & LPad(intMinutes) & " m : " & LPad(intSeconds) & " s" 
End Function 
'************************************************************ 
Function LPad(v) 
LPad = Right("00" & v, 2) 
End Function 
'************************************************************ 
+0

非常感謝,Hackoo!這工作:) – Philippe 2015-03-08 17:38:21

相關問題