Convert Unix/Windows timestamps to a DateTime PowerShell Object.
Get Unix/Windows time from a PowerShell DateTime Object.
Four cmdlets (two with optional switches to return conversion result as UTC time).
- Convert-UnixTime
- Convert-WindowsTime
- Get-UnixTime
- Get-WindowsTime
Available in the PowerShell Gallery
Install direct from the PowerShell Gallery (Powershell 5.x and above)
install-module -name ConvertTime
Convert from Unix timestamp to a PowerShell DateTime Object relative to local time based of system time zone.
(optional) Return DateTime as Coordinated Universal Time
The unix timestamp to convert
(optional) The unix timestamp converted and retured as Coordinated Universal Time
Token from Pipeline.
PowerShell Object
Convert-UnixTime 1592001868
Convert-UnixTime 1592001868 -UTC
PS C:\Users\Darren Robinson> Convert-UnixTime 1592001868
Saturday, 13 June 2020 8:44:28 AM
PS C:\Users\Darren Robinson> Convert-UnixTime 1592001868 -UTC
Friday, 12 June 2020 10:44:28 PM
Convert from Windows timestamp to a PowerShell DateTime Object relative to local time based of system time zone.
(optional) Return DateTime as Coordinated Universal Time
The Windows timestamp to convert
(optional) The Windows timestamp converted as Coordinated Universal Time
Token from Pipeline.
PowerShell Object
Convert-WindowsTime 132947402891099830
Convert-WindowsTime 132947402891099830 -UTC
PS C:\Users\Darren Robinson> Convert-WindowsTime 132947402891099830
Monday, 18 April 2022 5:24:49 PM
PS C:\Users\Darren Robinson> Convert-WindowsTime 132947402891099830 -UTC
Monday, 18 April 2022 7:24:49 AM
Convert from a PowerShell DateTime Object to Unix timestamp
(optional) If no input PowerShell DateTime Object provided the current datetime is converted
Token from Pipeline.
Unix datetime stamp
Get-UnixTime
PS C:\Users\Darren Robinson> Get-UnixTime
1665374881
PS C:\Users\Darren Robinson> Get-Date | Get-UnixTime
1665374931
PS C:\Users\Darren Robinson> Get-UnixTime -datetime 'Sunday, 9 October 2022 2:47:48 PM'
1665287268
Convert from a PowerShell DateTime Object to Windows timestamp
(optional) If no input PowerShell DateTime Object provided the current datetime is converted
Token from Pipeline.
Windows datetime stamp
Get-WindowsTime
PS C:\Users\Darren Robinson> Get-WindowsTime
133098487061671481
PS C:\Users\Darren Robinson> Get-Date | Get-WindowsTime
133098487250480096
PS C:\Users\Darren Robinson> Get-WindowsTime -datetime 'Sunday, 9 October 2022 2:47:48 PM'
133097608680000000