在 PowerShell 中解释 Get-Date 函数。


PowerShell中的Get-Date函数用于获取当前系统日期和时间。例如,当您仅仅键入Get-Date时,输出结果为:

Get-Date


PS C:\WINDOWS\system32> Get-Date
18 March 2020 19:17:03

当您检查(Get-Date)函数的类型时,它为DateTime

(Get-Date).GetType()
PS C:\WINDOWS\system32> (Get-Date).GetType()
IsPublic IsSerial    Name       BaseType
-------- --------    ----       --------
True     True        DateTime    System.ValueType

当您检查(Get-Date)的所有属性:

PS C:\WINDOWS\system32> Get-Date | fl * DisplayHint : DateTime
DateTime    : 18 March 2020 19:32:32
Date        : 18-03-2020 00:00:00
Day         : 18
DayOfWeek   : Wednesday
DayOfYear   : 78
Hour        : 19
Kind        : Local
Millisecond : 793
Minute      : 32
Month       : 3
Second      : 32
Ticks       : 637201567527939152 TimeOfDay : 19:32:32.7939152
Year        : 2020

您还可以获取上述单个属性。例如:

PS C:\WINDOWS\system32> (Get-Date).DayOfWeek
Wednesday


PS C:\WINDOWS\system32> (Get-Date).DayOfYear
78

更新于: 2020年3月20日

511 视图

启动你的事业

完成课程后获得认证

开始
广告
© . All rights reserved.