Converting Seconds to Years, days, hours, min, secs

[亡魂溺海] 提交于 2021-02-11 15:33:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!