Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Unix Timestamp to Datetime in Powershell

How to convert Unix timestamp to Datetime in Powershell

🎈 🎈 🎈
+1

    # Convert Unix timestamp to Date
    $unixTimestamp = 1642272414  
    $date = (Get-Date "1970-01-01 00:00:00").AddSeconds($unixTimestamp)
    
    Write-Output "Converted Date: $date"            
        

Output:
Converted Date: 2022-01-15 18:46:54
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this Powershell example, the Unix timestamp 1642272414 is added to the Unix epoch (1970-01-01 00:00:00) using the AddSeconds method. The result is a DateTime object representing the date and time in PowerShell.
The result is printed as a human-readable date using Write-Output which returns 2022-01-15 18:46:54.


Other useful Powershell date functions

Function Description Example
Get-Date Returns the current date and time or a specified date. Get-Date "2018-07-15 12:30:45" returns 2018-07-15 12:30:45
AddSeconds() Adds a number of seconds to a DateTime object. (Get-Date).AddSeconds(86400) adds 1 day to the current date.
AddDays() Adds a number of days to a DateTime object. (Get-Date).AddDays(7) adds 7 days to the current date.
AddHours() Adds a number of hours to a DateTime object. (Get-Date).AddHours(3) adds 3 hours to the current time.
TotalSeconds Returns the total seconds between two dates. ($date - $unixEpoch).TotalSeconds returns the seconds between two dates.
Set-Date Changes the system date and time to a specified date and time. Set-Date "2024-08-28 12:00:00" sets the system date to 2024-08-28 12:00:00.
ToString() Formats a DateTime object into a string using a specified format. (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") returns 2024-08-28 12:34:56
New-TimeSpan Calculates the difference between two dates. New-TimeSpan -Start (Get-Date "2018-01-01") -End (Get-Date "2020-01-01") returns the difference between the two dates.
Get-ItemProperty Retrieves system or file date properties (e.g., created or modified dates). Get-ItemProperty "C:\file.txt" | Select-Object LastWriteTime
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder