Unix timestamps in 10 languages.
Every language gets the current epoch, converts to and from dates, and handles timezones differently, and every one of them has a classic bug hiding in the seconds-vs-milliseconds or naive-vs-aware distinction. Pick your stack:
JavaScript
Date.now() is milliseconds, Date is always an instant, parse and format without the unit mix-up.
/programming/javascript-unix-timestamp/ →
Python
fromtimestamp returns naive local time; timestamp() on naive objects assumes local. Aware datetimes only.
/programming/python-unix-timestamp/ →
PHP
time() for seconds, microtime(true) for fractions, and a global default timezone that shifts every DateTime.
/programming/php-unix-timestamp/ →
SQL
UNIX_TIMESTAMP vs EXTRACT(EPOCH) vs strftime, and the session-timezone trap in MySQL.
/programming/sql-unix-timestamp/ →
Go
Unix(), UnixMilli(), and UnixMicro() accessors; time.Parse defaults to UTC, use ParseInLocation.
/programming/go-unix-timestamp/ →
Java
Instant for the epoch, LocalDateTime is deliberately naive, and currentTimeMillis is the fast ms path.
/programming/java-unix-timestamp/ →
C#
DateTimeOffset owns the Unix helpers; DateTime.Kind=Unspecified silently means local.
/programming/csharp-unix-timestamp/ →
Rust
SystemTime + duration_since(UNIX_EPOCH), and chrono types that make naive time a compile-time decision.
/programming/rust-unix-timestamp/ →
C++
time(nullptr), std::chrono casts, and the timegm-vs-mktime UTC/local trap.
/programming/cpp-unix-timestamp/ →
PowerShell
[DateTimeOffset]::UtcNow.ToUnixTimeSeconds(), the offset type is the only timezone-safe one.
/programming/powershell-unix-timestamp/ →
The pattern, once
Underneath every language's API the same three operations appear: read the clock
(usually seconds, sometimes milliseconds), build a date object from the number,
and format it in a zone. The differences that matter are the unit
(Date.now() is ms, time() is seconds), and whether the
language's date type is naive by default.
# 1, current epoch
seconds # 1767225600
milliseconds # 1767225600123
# 2, timestamp → date, always in UTC first
utc = to_utc_datetime(1767225600)
# 3, display in any zone
utc.in_zone("Asia/Kolkata") # 2026-01-01 05:30:00 +05:30
# 4, date → timestamp: pin the zone BEFORE converting
utc_datetime(2026-01-01 00:00:00).epoch
Prefer a tool to a function call? The main epoch converter does all four steps in your browser, with the live snippet tabs on the homepage showing the current value in each language.