One of my team members was recently required to get date in 24-hour format in PowerShell. I suggested a solution. If you’re working with PowerShell and need to display the current date and time in a 24-hour format, then read this complete tutorial.
To display the current date and time in 24-hour format using PowerShell, you can use the Get-Date cmdlet with the -Format parameter. The command Get-Date -Format "MM/dd/yyyy HH:mm:ss" will output the date and time in the desired format, where MM represents the month, dd the day, yyyy the year, HH the hour in 24-hour format, mm the minutes, and ss the seconds.
PowerShell Get-Date 24 Hour Format
The Get-Date cmdlet in PowerShell is used to retrieve the current date and time or a specified date and time. It can also format the output in various ways, including 24-hour format.
The basic syntax for Get-Date is:
Get-DateThis command returns the current date and time. However, to customize the format, we need to use the -Format parameter.
Format Date and Time in 24-Hour Format
To display the date and time in a 24-hour format, you can use the -Format parameter with a specific format string. Here’s the syntax:
Get-Date -Format "MM/dd/yyyy HH:mm:ss"In this format string:
MMrepresents the month.ddrepresents the day.yyyyrepresents the year.HHrepresents the hour in 24-hour format.mmrepresents the minutes.ssrepresents the seconds.
Here is the output in the screenshot below:

Examples
Let’s dive into some practical examples to see how this works.
Example 1: Display Current Date and Time
To display the current date and time in 24-hour format, you can use the following command:
Get-Date -Format "MM/dd/yyyy HH:mm:ss"This will output something like:
09/15/2024 14:35:47Check out How to Format Date in PowerShell
Example 2: Store the Formatted Date and Time in a Variable
You might want to store the formatted date and time in a variable for later use. Here’s how you can do it:
$currentDateTime = Get-Date -Format "MM/dd/yyyy HH:mm:ss"
Write-Output $currentDateTimeThis will store the formatted date and time in the $currentDateTime variable and then print it.
Here is the output in the screenshot below:

Example 3: Using Custom Date and Time
If you need to work with a specific date and time, you can create a DateTime object and format it. For example, let’s say you want to format the date and time for July 4th, 2025, at 18:30:00:
$customDate = Get-Date "07/04/2025 18:30:00"
$customDate.ToString("MM/dd/yyyy HH:mm:ss")This will output:
07/04/2025 18:30:00Check out Get Date Without Time in PowerShell
Advanced Formatting with UFormat
Another method to format the date and time in PowerShell is by using the -UFormat parameter, which is based on Unix strftime formatting. Here’s how you can use it:
Get-Date -UFormat "%m/%d/%Y %H:%M:%S"In this format string:
%mrepresents the month.%drepresents the day.%Yrepresents the year.%Hrepresents the hour in 24-hour format.%Mrepresents the minutes.%Srepresents the seconds.
This approach is particularly useful if you’re familiar with Unix-style date formatting.
Conclusion
In this tutorial, I have explained how to get date and time in 24-Hour format in PowerShell. Whether you’re logging events, scheduling tasks, or simply need to display the current date and time, understanding how to format the output in a 24-hour format is crucial.
By using the -Format or -UFormat parameters, you can easily customize the date and time in a 24-hour format.
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.