Vba 将秒转换为年、天、小时、分钟、秒
我有很多东西要把秒转换成小时、分钟和秒 我需要让它工作几年,甚至几天 有人能帮忙吗Vba 将秒转换为年、天、小时、分钟、秒,vba,visual-studio-2012,Vba,Visual Studio 2012,我有很多东西要把秒转换成小时、分钟和秒 我需要让它工作几年,甚至几天 有人能帮忙吗 Dim mHours As Long, mMinutes As Long, mSeconds As Long mSeconds = 12345 ' Sample data mHours = mSeconds \ 3600 mMinutes = (mSeconds - (mHours * 3600)) \ 60 mSeconds = mSeconds - ((mHours * 3600) + (mMinutes *
Dim mHours As Long, mMinutes As Long, mSeconds As Long
mSeconds = 12345 ' Sample data
mHours = mSeconds \ 3600
mMinutes = (mSeconds - (mHours * 3600)) \ 60
mSeconds = mSeconds - ((mHours * 3600) + (mMinutes * 60))
MsgBox mHours & ":" & mMinutes & ":" & mSeconds
我假设每年有365.25天谢谢大家,我最终使用了Mod功能
If (seconds >= 31536000) Then
years = seconds \ 31536000
seconds = seconds Mod 31536000
End If
If (seconds >= 86400) Then
days = seconds \ 86400
seconds = seconds Mod 86400
End If
谢谢你的帮助:)什么是“\”?不应该是“/”?@Maertin@Ansgar Wiechers他为什么用反斜杠?他只是想除掉两个整数,得到另一个整数?@Maertin如果你想除掉整数得到一个整数结果,你想用整数除法。进行浮点除法并让解释器在Long和Double之间来回转换值没有多大意义。@Ansgar Wiechers我不知道整数除法。我只知道常规浮点除法,希望它能自动施放。非常感谢。
If (seconds >= 31536000) Then
years = seconds \ 31536000
seconds = seconds Mod 31536000
End If
If (seconds >= 86400) Then
days = seconds \ 86400
seconds = seconds Mod 86400
End If