Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find time in milliseconds using PowerShell?

How can I find the time in milliseconds using PowerShell?

like image 428
Mulesoft Developer Avatar asked Jan 30 '12 06:01

Mulesoft Developer


2 Answers

You can get the full date with milliseconds with the following:

Get-Date -Format HH:mm:ss.fff
like image 137
freakydinde Avatar answered Nov 13 '22 05:11

freakydinde


The question suggests finding a given datetime in milliseconds (Microsoft epoch time). This is easily solved with:

[Math]::Round((Get-Date).ToFileTime()/10000)

or

[Math]::Round((Get-Date).ToFileTimeUTC()/10000)

To convert this to Unix epoch time in seconds:

[Math]::Round((Get-Date).ToFileTime() / 10000000 - 11644473600)

Where 11644473600 is the number of elapsed seconds between the Microsoft epoch (January 1, 1601 A.D. (C.E.)) and the Unix epoch (January 1, 1970, 12AM UTC/GMT)

https://msdn.microsoft.com/en-us/library/system.datetime.tofiletime(v=vs.110).aspx

like image 14
Brian McMahon Avatar answered Nov 13 '22 06:11

Brian McMahon