PowerShell: Date Time

By Xah Lee. Date: . Last updated: .

use Get-Date to get current date time.

# print today's date

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 formats:

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

Example in script

$x = "Started: "+ (Get-Date -Format "yyyy-MM-ddTHH:mmK")

Parse Date

$xDateObj = [datetime]::ParseExact("2021-12-11 01:00:00", "yyyy-MM-dd hh:mm:ss", [Cultureinfo]::InvariantCulture)

PowerShell: Date/Time

PowerShell How-To

Install and Help

list files

list dirs

on dir

on file

Windows config

zip tar