Retrieving the current date and time on a Windows system is crucial for system administration, scripting, and logging. The PowerShell Get-Date
command enables users to display and format the date and time efficiently. This tutorial shows how to get current date and time on Windows.
1. Current date and time (Local)
To get the current date and time in your local timezone, run:
Get-Date
Example output:
Sunday, February 2, 2025 01:37:54
2. Current date and time (UTC)
If you need the current date and time in Coordinated Universal Time (UTC), use:
(Get-Date).ToUniversalTime()
Example output:
Sunday, February 2, 2025 06:37:54
3. Current date and time in ISO 8601 format (Local)
To display the current date and time in your local timezone with ISO 8601 format, you can use:
Get-Date -Format "yyyy-MM-ddTHH:mm:ssK"
Example output:
2025-02-02T01:37:54-05:00
4. Current date and time in ISO 8601 format (UTC)
To retrieve the current date and time in UTC using ISO 8601 format, run:
(Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss+00:00")
Example output:
2025-02-02T06:37:54+00:00
Leave a Comment
Cancel reply