See Also Example
Returns the current system time.
Syntax
Time[$][( )]
Remarks
Time returns a Variant
The Time$ function returns an eight-character string of the form hh:mm:ss, where hh is the hour (00-23), mm is the minute (00-59), and ss is the second (00-59). A 24-hour clock is used; therefore, 8:00 P.M. appears as 20:00:00.
The output of the Time$ function is equivalent to:
Format$(Now,"hh:mm:ss")
To set the system time, use the Time$ statement.
Date, Date$ Functions
Date, Date$ Statements
Time, Time$ Statements
Timer Function
The example uses the Time function to provide the default time for the input box when prompting the user for a new time. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Msg, NewTime ' Declare variables.
Msg = "Enter a new time in the form hh:mm:ss"
NewTime = InputBox(Msg, "", Time) ' Get user input.
If Len(NewTime) > 0 Then ' Check if valid.
Time = NewTime ' Set time.
Msg = "System time now set to "
Msg = Msg & Time & "." ' Put time in message.
Else
Msg = "You did not enter a valid time."
End If
MsgBox Msg ' Display message.
End Sub