请教用VB编算计算机加电时间的程序

解决方案 »

  1.   

    Option Explicit
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Dim STime As DatePrivate Sub Form_Load()
        Me.Move Screen.Width - Me.Width - Me.Width \ 2, 0
        STime = DateAdd("s", -(GetTickCount \ 1000), Now)
    End SubPrivate Sub Timer1_Timer()
        Dim T As String
        Dim S As Long
        Dim nT As Date
        
        S = GetTickCount \ 1000
        nT = DateAdd("s", S, "00:00:00")
        T = "您的电脑是在:" & vbCrLf & IIf(Check1.Value, Format(STime, "yyyy-m-d hh:mm:ss AM/PM"), STime) & "启动的。" & vbCrLf
        T = T & "现在的时间是:" & vbCrLf & IIf(Check1.Value, Format(Now, "yyyy-m-d hh:mm:ss AM/PM"), Now) & vbCrLf
        T = T & "总共运行了:" & vbCrLf
        T = T & S \ 1440000 & "天 " & Hour(nT) & "小时 "
        T = T & Minute(nT) & "分 "
        T = T & Second(nT) & "秒" & vbCrLf & vbCrLf
        T = T & "共计:" & S \ 60 & "分钟"
        Text1.Text = T
    End Sub