Redigera

Dela via


DateAndTime.DateString Property

Definition

Returns or sets a string value representing the current date according to your system.

public:
 static property System::String ^ DateString { System::String ^ get(); void set(System::String ^ value); };
public static string DateString { get; [System.Runtime.Versioning.SupportedOSPlatform("windows")] set; }
public static string DateString { get; set; }
[<set: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member DateString : string with get, set
static member DateString : string with get, set
Public Property DateString As String

Property Value

Returns or sets a string value representing the current date according to your system.

Attributes

Exceptions

Invalid format used to set the value of DateString.

Examples

The following example uses the DateString property to display the current system date.

MsgBox("The current date is " & DateString)

Remarks

DateString returns the system date in the MM-dd-yyyy format, which uses the abbreviated month name. The accepted formats for the date are M-d-yyyy, M-d-y, M/d/yyyy, and M/d/y. This is true for all system locales except those that use a double-byte character set (DBCS). If the system locale uses a double-byte character set, DateString returns the system date in the yyyy-MM-dd format. The system locale is set by using the Clock, Language, and Region item in Control Panel.

Note The DateString property returns the system date only in the yyyy-MM-dd format for the zh (Chinese simplified), ko (Korean), and ja (Japanese) system locales if you are running Visual Basic within Silverlight.

To get or set the current system time as a String, use the TimeString 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 a predefined or user-defined date/time format. The following example demonstrates this.

MsgBox("The formatted date is " & Format(Now, "dddd, d MMM yyyy"))  

To access the current system date as a Date, use the Today property.

Important

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.

Applies to

See also