DateAndTime.TimeString 属性

定义

根据系统返回或设置表示当前时间的字符串值。

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

属性值

根据系统返回或设置表示当前时间的字符串值。

属性

例外

用于设置 TimeString 值的格式无效。

示例

此示例使用 TimeString 属性显示当前系统时间。

MsgBox("The current time is " & TimeString)

注解

TimeString 始终将系统时间返回为“HH:mm:ss”,这是一种 24 小时格式。 此格式是区域性固定格式,这意味着即使更改 控制面板 中的区域选项,它也不会更改。

若要获取或设置当前系统日期作为 String,请使用 DateString 属性。

若要以区域设置的格式或自定义格式获取当前系统日期或时间,请向 Format 函数提供 Now 属性,并指定预定义或用户定义的日期/时间格式。 下面的示例演示这一操作。

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

若要以 的形式 Date访问当前系统时间,请使用 TimeOfDay 属性。

重要

设置系统日期或时间需要非托管代码权限,这可能会影响其在部分信任情况下的执行。 有关详细信息,请参阅 SecurityPermission代码访问权限

适用于

另请参阅