Epoch & Unix Timestamp in Rust

Get the current epoch timestamp

use std::time::{SystemTime, UNIX_EPOCH};

let epoch_seconds = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();

Convert epoch to date

use chrono::DateTime;

let dt = DateTime::from_timestamp(1718200000, 0).unwrap();

Convert date to epoch

use chrono::{TimeZone, Utc};

let epoch = Utc.with_ymd_and_hms(2026, 6, 12, 0, 0, 0).unwrap().timestamp();

Rust notes

std handles 'now' but date arithmetic needs the chrono crate. duration_since(UNIX_EPOCH) errors if the clock reads before 1970 — handle rather than unwrap in production.

Check any value live with the epoch converter, or read what Unix time actually counts.

Other languages

C · C# · C++ · Dart · Go · Java · JavaScript · Kotlin · MySQL · Perl · PHP · PostgreSQL · Python · R · Ruby · Scala · SQLite · Swift · TypeScript