For Developers
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()
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.
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
Every language's snippets side by side, for quick comparison.
Convert any timestamp instantly, no code required.
The .NET DateTimeOffset API these PowerShell snippets are built on.