Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get current time in FILETIME format?

How can I use Powershell/CMD on Windows to get the current time in the Windows FILETIME format? Something like this answer about Linux except for Windows, using the Windows FILETIME format (time since 1600 in 100-nanosecond intervals), and preferably something simple like the aforementioned answer.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# Returns a FILETIME timestamp representing the current UTC timestamp,
# i.e. a [long] value that is the number of 100-nanosecond intervals 
# since midnight 1 Jan 1600, UTC.
[datetime]::UtcNow.ToFileTime()

Alternatives: [dateime]::Now.ToFileTimeUtc() or [datetimeoffset]::Now.ToFileTime()

To convert such a FILETIME value back to a [datetime] instance:

[datetime]::FromFileTime(
  [datetime]::UtcNow.ToFileTime()
)

Note: The above yields a local [datetime] instance (its .Kind property is Local); alternatively, use [datetimeoffset]::FromFileTime(), which allows you to obtain a local (.LocalDateTime) or a UTC (.UtcDateTime]) [datetime] instance, as needed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading