我在几分钟内从Web服务获得返回值,例如538分钟.我需要在几小时和几分钟内解决这个问题.什么是最快的方式,在.net代码和VB6代码(两个应用程序使用该服务)将其从分钟转换为HH:mm?
谢谢
Wil*_*ler 12
此代码应该在.NET和VB6中都有效:
Dim hours As Integer = 538 \ 60
Dim minutes As Integer = 538 - (hours * 60)
Dim timeElapsed As String = CType(hours, String) & ":" & CType(minutes, String)
label1.Text = timeElapsed
Run Code Online (Sandbox Code Playgroud)
在.NET中,您应该能够执行以下操作(需要进行测试):
Dim timeElapsed As DateTime = New DateTime(1, 1, 1, 0, 538, 0)
label1.Text = timeElapsed.ToString("HH:mm")
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助!
在.Net中,您有一个TimeSpan类,因此您可以执行以下操作
Dim t As New TimeSpan(0, 538, 0)
'Then you have the 2 properties
t.Hours
t.Minutes
Run Code Online (Sandbox Code Playgroud)
在VB6中你可以使用 Format(538/1440.0, "hh:mm")
VB6 Date值可以被视为几天,一天中有1440分钟.所以538/1440是你这个时期的天数,然后就可以使用了Format