在 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.