Epoch Converter and Date/Time in Powershell

Quick Navigation

Getting DateTime Object

The Get-Date command gets a DateTime object that represents the date and time.



    Get-Date -DisplayHint Date
    Get-Date -Format g
    Get-Date -UFormat "%Y / %m / %d / %A / %Z"
    Get-Date -Date "01/01/1970"

                

Output:



    Saturday, February 16, 2019
    2/16/19 4:46 AM
    2019 / 02 / 16 / Saturday / +00
    Thursday, January 1, 1970 12:00:00 AM

                


From Date to Unix Time



    Get-Date -Date "02/15/2019" -UFormat %s

                

Output:



    1550188800

                


From Unix Time to Date


    #starting from the start epoch time January 1, 1970, add the seconds to it
    $oUNIXDate=(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds(1550293345))
    $oUNIXDate #display value

                

Output:



    Saturday, February 16, 2019 5:02:25 AM

                


Programming Languages: