powershelltimestampmilliseconds

Powershell - Adding milliseconds to timestamp


I am trying to create a timestamp string in the format:

yyyymmddhhmmssfff

where f is milliseconds.

Example: 20171013180359235

So far I have

[string]$Date = Get-Date -UFormat "%Y%m%d%H%M%S"

With this I get only up to the seconds. I know if I add %l to the end I get a precision of 2 milliseconds, but I am one short. Is there any way to describe how precise I can choose the milliseconds. Thanks


Solution

  • Using the .tostring() method of the datetime object:

     (get-date).ToString('yymmddhhmmssfff')
    

    171513121549340