Functions/Data/Convert-TimeFormat.ps1

function Convert-TimeFormat
    { 
    [cmdletbinding(DefaultParameterSetName="DateTime")]
    param
        (
        # Epoch Time Input (in Seconds)
        [parameter(Mandatory=$false,ParameterSetName="Epoch")]
        [int64]
        $EpochTime = 0,

        # DateTime Input
        [parameter(Mandatory=$false,ParameterSetName="DateTime")]
        [Datetime]
        $DateTime = (get-date),

        # Origin Time
        [Parameter(Mandatory=$False)]
        [ValidateSet("1601","1970")]
        [string]
        $OriginYear = "1970",

        # Format to express
        [Parameter(Mandatory=$False)]
        [ValidateSet("DateTime","Epoch")]
        [String]
        $OutputFormat = "DateTime"
        )
    Process
        {
        # Establish Origin
        $Origin = New-Object -Type DateTime -ArgumentList $OriginYear, 1, 1, 0, 0, 0, 0

        # Switch on Input Format
        $DTG = switch ($PSCmdlet.ParameterSetName)
            {
            "Epoch" {$Origin.AddSeconds($EpochTime)}
            "DateTime" {$DateTime}
            }
        
        # Switch on Output Format
        switch ($OutputFormat)
            {
            "Epoch" {($DTG - $origin).totalseconds}
            "DateTime" {$DTG}
            }
        }
    }