简体   繁体   中英

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.

# 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() to obtain an unambiguous timestamp, which can be used as-is or converted to a local ( .LocalDateTime ) or a UTC ( .UtcDateTime ) [datetime] instance, as needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM