DateAndTime.TimeOfDay 属性
定义
返回或设置 Date 值,该值包含与系统对应的当前时间。Returns or sets a Date value containing the current time of day according to your system.
public:
static property DateTime TimeOfDay { DateTime get(); void set(DateTime value); };
[set: System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static DateTime TimeOfDay { get; set; }
public static DateTime TimeOfDay { get; set; }
[<set: System.Runtime.Versioning.SupportedOSPlatform("windows")>]
member this.TimeOfDay : DateTime with get, set
member this.TimeOfDay : DateTime with get, set
Public Property TimeOfDay As DateTime
属性值
返回或设置 Date 值,该值包含与系统对应的当前时间。Returns or sets a Date value containing the current time of day according to your system.
- 属性
示例
此示例使用 TimeOfDay 属性返回当前系统时间。This example uses the TimeOfDay property to return the current system time.
Dim currentTime As Date
currentTime = TimeOfDay
注解
Date数据类型包括日期部分。The Date data type includes date components. 返回系统时间时, TimeOfDay 将这些值全部设置为1,因此返回的值表示第1年的第一天。When returning the system time, TimeOfDay sets these all to 1, so the returned value represents the first day of the year 1. 设置系统时间时,将 TimeOfDay 忽略日期部分。When setting the system time, TimeOfDay ignores the date components.
若要以形式访问当前系统时间 String ,请使用 TimeString 属性。To access the current system time as a String, use the TimeString property.
若要获取或设置当前系统日期,请使用 Today 属性。To get or set the current system date, use the Today property.
重要
设置系统日期或时间需要非托管代码权限,这可能会影响在部分信任情况下的执行。Setting the system date or time requires unmanaged code permission, which might affect its execution in partial-trust situations. 有关详细信息,请参阅 SecurityPermission 和 代码访问权限。For more information, see SecurityPermission and Code Access Permissions.