PowerShell: Date Time
Get-Date Command
use Get-Date
to get current date time.
Get-Date # Monday, September 9, 2024 10:04:20 AM
ISO 8601 Date Time Format
Get-Date -Format "yyyy-MM-dd" # 2021-05-11
Get-Date -Format "yyyyMMdd" # 20210511
Get-Date -Format "yyyy-MM-ddTHH:mmK" # 2021-05-11T14:42-07:00
Other Common Formats
# common datetime string in programing Get-Date -Format "yyyy-MM-dd_HHmmss" # 2024-09-09_100239
Get-Date -Format "yyyy-MM-dd dddd" # 2021-05-11 Tuesday
Get-Date -Format "dddd MM/dd/yyyy HH:mm K" # Tuesday 05/11/2021 14:44 -07:00
Parse Date
$xDateObj = [datetime]::ParseExact("2021-12-11 01:00:00", "yyyy-MM-dd hh:mm:ss", [Cultureinfo]::InvariantCulture)