问题
I have this much to convert seconds to hours, minutes, and seconds.
I need to make it work for years, and days too.
Can someone help?
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
回答1:
Thanks Everyone, I ended up using the Mod function.
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
Thanks for all the help :)
回答2:
Dim mHours As Long, mMinutes As Long, mSeconds As Long, mDays as Long, mYears as Long
mSeconds = 12345 ' Sample data
mHours = mSeconds / 3600
mMinutes = (mSeconds - (mHours * 3600)) / 60
mSeconds = mSeconds - ((mHours * 3600) + (mMinutes * 60))
MsgBox mHours & ":" & mMinutes & ":" & mSeconds
mDays = mSeconds / 86400
mYears = mSeconds / 31557600
I am assuming each year has 365.25 days
来源:https://stackoverflow.com/questions/34667431/converting-seconds-to-years-days-hours-min-secs