Plex beginsAT time

How does on convert the BeginsAt time to localtime. No matter what I try it converts to 21:00 when it should be 22:00 when using powershell.

Adapted from some Stack Overflow proposals (though I’ve done similar in C#):

# Get DateTime object representing 1/1/1970 at midnight
$epoch = New-Object -Type DateTime 1970, 1, 1, 0, 0, 0, 0

# Add Unix epoch timestamp to the origin time, result is UTC
$timestamp = $epoch.AddSeconds(1744050670)

# Convert timestamp to local time
$timestamp_local = [TimeZone]::CurrentTimeZone.ToLocalTime($timestamp)

# Print result
$timestamp_local

# Just the time as a string, in 24 hour format
$time_string = $timestamp_local.ToString("HH:mm")

This assumes that the beginsAt value you’re pulling is indeed a Unix timestamp (as are most in the Plex databases these days).

[Edit]
Or, most of the above in one step (plus the string conversion):

$beginsAt = Get-Date -UnixTimeSeconds 1744050670

$beginsAtStr = $beginsAt.ToString("HH:mm")

Thanks that works. I spent an hour or more with copilot giving me scripts that always were one hour off.

You’re welcome, glad you got it working!