Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

TimeString Property 

Returns or sets a String value representing the current time of day according to your system.


Public Property TimeString As String
Exception type Error number Condition

InvalidCastException

5

Invalid format used to set value of TimeString.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

TimeString always returns the system time as "HH:mm:ss", which is a 24-hour format. This format is culture-invariant, which means it does not change even if you change the Regional Options in Control Panel.

To get or set the current system date as a String, use the DateString Property.

To get the current system date or time in the format of your locale, or in a custom format, supply the Now Property to the Format Function, specifying either Predefined Date/Time Formats (Format Function) or User-Defined Date/Time Formats (Format Function). The following example demonstrates this.

MsgBox("The formatted time is " & Format(Now, "hh.mm.ss.fff tt"))

To access the current system time as a Date, use the TimeOfDay Property.

Security noteSecurity Note

Setting the system date or time requires unmanaged code permission, which might affect its execution in partial trust situations. For more information, see SecurityPermission and Code Access Permissions.

This example uses the TimeString property to display the current system time.

MsgBox("The current time is " & TimeString)

Namespace: Microsoft.VisualBasic

Module: DateAndTime

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Because TimeString is a member of a module, rather than of a class, you do not need to create an object on which to access TimeString.

You can get, but not set, the system time using the TimeString property.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.