For Developers

Unix Timestamp in PowerShell

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in PowerShell — plus the local-vs-UTC default that quietly shifts every script's output.

[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
$ts = 1750000000
[DateTimeOffset]::FromUnixTimeSeconds($ts).UtcDateTime
$dt = Get-Date "2025-06-15T12:00:00Z"
$dto = [DateTimeOffset]::Parse($dt)
$dto.ToUnixTimeSeconds()

The PowerShell-specific pitfall

Get-Date with no arguments returns local time, and piping it straight into a Unix-timestamp conversion silently bakes in whatever timezone the machine running the script happens to be set to — which is a different bug on a laptop than on a scheduled task running on a server in another region. [DateTimeOffset]::UtcNow and .ToUnixTimeSeconds() sidestep this entirely by being explicit about UTC at every step, and are the safer default for anything that writes a timestamp somewhere another system will read it back.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading