EpochTools

Code snippets / Rust

How to get the current Unix timestamp in Rust

The standard library exposes epoch seconds through `SystemTime::now().duration_since(UNIX_EPOCH)`. For ergonomic formatting most projects reach for the `chrono` crate.

`chrono::DateTime::<Utc>::from_timestamp(secs, 0)` builds a UTC instant directly from epoch seconds.

Current Unix timestamp (seconds)

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

let secs = SystemTime::now()
    .duration_since(UNIX_EPOCH)
    .unwrap()
    .as_secs();
println!("{}", secs); // 1,754,136,000

Convert epoch seconds → ISO 8601 (UTC)

use chrono::{DateTime, Utc};
let dt = DateTime::<Utc>::from_timestamp(1754136000, 0).unwrap();
println!("{}", dt.to_rfc3339()); // 2025-08-02T12:00:00+00:00

Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z

Need more languages? Browse all the Unix timestamp code snippets. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.

Epoch → Human Date

Try it live — convert any timestamp in Rust-friendly format.

Seconds or milliseconds — the unit is auto-detected. Example: 1735689600

Waiting for input…

UTC ISO 8601

Local — auto

RFC 2822 / GMT

Seconds value

Relative time