解释 PowerShell 中的 Get-Date 函数。
powershellmicrosoft technologiessoftware & coding更新于 2026/1/11 20:22:17
Get-Date 函数在 PowerShell 中用于获取当前系统日期和时间。例如,当您简单输入 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

