Get-Date cmdlet is versatile and can be used to display the current date and time with the level of precision you require. This post will explore how to format the
Get-Date cmdlet output to include milliseconds. Here is an example of “PowerShell get-date format milliseconds“.
PowerShell get-date format milliseconds
Get-Date is a cmdlet in PowerShell that retrieves the current date and time from the system. It is extremely flexible, allowing you to format the output in various ways, and it can also be used to create date and time objects for use in scripts and automation.
Get-Date does not display milliseconds. To include milliseconds in the output, you need to use the
-Format parameter with a format string that includes the milliseconds format specifier (
Here’s a simple example to display the current time with milliseconds:
Get-Date -Format HH:mm:ss.fff
This command will output something like
123 represents the milliseconds.
Formatting the Date with Milliseconds
If you want to display the full date along with the time and milliseconds in PowerShell, you can extend the format string to include date specifiers:
Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
This will produce an output like
2024-01-05 14:58:31.123, which includes the year, month, day, hours, minutes, seconds, and milliseconds.
Using Milliseconds in Calculations
Sometimes, you might want to perform calculations or comparisons with times, including milliseconds. To do this, you can use
Get-Date to create a DateTime object and then work with its properties. For instance:
$currentTime = Get-Date
Millisecond property of a DateTime object will return an integer between 0 and 999 that represents the milliseconds of the current time
Formatting dates and times with milliseconds in PowerShell is straightforward once you know the correct format specifiers. With the Get-Date cmdlet and the .fff format specifier, you have the tools you need to work with milliseconds in your PowerShell scripts. I hope you know now that “PowerShell get-date format milliseconds.”
You may also like:
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com