将秒数转换为年,日,小时,分钟,秒

时间:2016-01-08 00:06:31

标签: vba visual-studio-2012

我有这么多将秒转换为小时,分钟和秒。

我需要让它工作多年,也需要几天。

有人可以帮忙吗?

Private Sub createEmail(ByVal toEmailAddresses As String, _
                    ByVal ccEmailAddresses As String, _
                    ByVal att1 As String, _
                    ByVal att2 As String, _
                    ByVal signature As String, _
                    ByVal subject As String, _
                    ByVal displayIt As Boolean)
    On Error GoTo foundError
    Dim outItem As Outlook.MailItem
    Set outItem = Outlook.CreateItem(olMailItem)

    outItem.BodyFormat = olFormatHTML
    outItem.Recipients.Add toEmailAddresses
    outItem.cc = ccEmailAddresses
    outItem.subject = subject
    If att1 <> "" Then
        outItem.Attachments.Add (att1)
    End If
    If att2 <> "" Then
        outItem.Attachments.Add (att2)
    End If

    outItem.HTMLBody = signature

    outItem.Send
    'Note: if you wanted to create the email and check it first, use outItem.Save
    Exit Sub
foundError:
    MsgBox "Error in createEmail: " + CStr(Err) + ", " + Error(Err), vbOKOnly, "ERROR"
End Sub

2 个答案:

答案 0 :(得分:0)

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 

我假设每年有365.25天

答案 1 :(得分:0)

谢谢大家,我最终使用了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

感谢所有帮助:)