For Developers

Unix Timestamp in Rust

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in Rust — plus the specific mistake that trips up Rust code more than any other.

use std::time::{SystemTime, UNIX_EPOCH};
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()
// with the `chrono` crate:
chrono::DateTime::from_timestamp(1750000000, 0)
// with the `chrono` crate:
chrono::DateTime::parse_from_rfc3339("2025-06-15T12:00:00Z").unwrap().timestamp()

The Rust-specific pitfall

The standard library's SystemTime deliberately has no built-in formatting or timezone handling at all — it's designed as an opaque, monotonic-ish measurement, not a calendar type. Almost every real Rust codebase reaches for the chrono or time crate the moment it needs to turn a timestamp into a human-readable date, rather than working with SystemTime directly.

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