请先登录 | 注册
MM0759.COM
059 - 自定义一个毫秒转时分秒函数 Sub MS2MHS(ms As Int) As String - 文章首页返回版区
■标题:059 - 自定义一个毫秒转时分秒函数 Sub MS2MHS(ms As Int) As String
■作者:IPSC [2025/3/26 18:41:09]
Sub Activity_Create(FirstTime As Boolean)


'Do not forget to load the layout file created with the visual designer. For example:





'Activity.LoadLayout("Layout1")




    Msgbox(MS2MHS(12345678),"毫秒转时分秒")  '返回 03:25:46

End Sub




'计算毫秒并转换格式为 时:分:秒

Sub MS2MHS(ms As Int) As String


Dim Seconds As Int, Minutes As Int,Hours As Int





Seconds = Round(ms / 1000) '将毫秒数除以1000转为秒(四舍五入)





Minutes = Floor(Seconds / 60) '将秒数除以60转为分钟





If Minutes>=60 Then





Hours=Floor(Minutes / 60)





Minutes=Minutes-Hours*60





End If





Seconds = Seconds Mod 60 '将总秒数除以60获得的余数就是秒数





Return NumberFormat(Hours,2, 0) & ":" & NumberFormat(Minutes, 2, 0) & ":" & NumberFormat(Seconds, 2, 0)




End Sub



回复/版区/上篇/下篇/发贴/仅文字/HTML
【倒序/最近21条回复】(暂无)
(查看完整版网页)



短讯|首页|登录|算法|电脑版 .
DK MiniBBS Plus v2.0
mm0759.com
31 毫秒 .