Change the date to the EPOCH format

For a recent project it is a requirement to change a date value to the EPOCH format. We need this EPOCH date format to automate the creation of a ticket in a Remedy system. The customer is using BMC Atrium Orchestration as a frontend to the Remedy system.

What is EPOCH Time?
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).

Why does EPOCH time start in 1970?
So no file can be created before 1970-01-01. … Unix was originally developed in the 60s and 70s so the “start” of Unix Time was set to January 1st 1970 at midnight GMT (Greenwich Mean Time) – this date/time was assigned the Unix Time value of 0. This is what is know as the Unix Epoch.

I’ve created a small PowerShell function to convert a Get-Date input to the EPOCH date/time format.

function ConvertTo-Epoch ([datetime]$InputEpoch) {
    [datetime]$Epoch = '1970-01-01 00:00:00'
    [int]$Ctime = ""

    $Ctime = (New-TimeSpan -Start $Epoch -End $InputEpoch).TotalSeconds
    return $Ctime
}

$a = ConvertTo-Epoch (get-date)

Tags:

Leave a Reply