Rust Unix Timestamp Converter

Convert Unix timestamps in Rust with live parser and chrono/std::time snippets. Seconds and milliseconds.

⏱ UnixLi — Live Tool All processing local · No data sent
—
unix seconds · now

Smart Universal Parser

// Paste Unix seconds/ms, ISO 8601, RFC 2822, or a human date.

Developer Snippets

// Copy-ready code — current timestamp injected automatically.

Unix timestamps in Rust

Rust gives you two good options for epoch time. The standard library’s std::time::SystemTime reads the clock and measures durations since UNIX_EPOCH, with no dependencies. The chrono crate adds calendar dates, formatting, parsing, and time zones. The live parser above checks any value you paste, and the snippet panel generates Rust code for both approaches. Everything runs in your browser, so no timestamp leaves the tab.

Standard library: SystemTime and UNIX_EPOCH

SystemTime::now().duration_since(UNIX_EPOCH) returns a Result<Duration, SystemTimeError>. It is an error only if the system clock is set before 1970, so handle it with expect and a clear message rather than a bare unwrap.

Rust (std only)
use std::time::{Duration, SystemTime, UNIX_EPOCH};

let since = SystemTime::now()
    .duration_since(UNIX_EPOCH)
    .expect("system clock is before 1970");
let secs: u64 = since.as_secs();     // e.g. 1715429912
let millis: u128 = since.as_millis();

// Unix seconds -> SystemTime
let t = UNIX_EPOCH + Duration::from_secs(1_715_429_912);

The standard library has no calendar formatting: it cannot print “2024-05-11” by itself. That is where chrono comes in.

chrono: DateTime::from_timestamp and Utc

With chrono = "0.4" in Cargo.toml, the current constructor is DateTime::from_timestamp(secs, nanos). It returns Option<DateTime<Utc>>, with None for out-of-range values:

Rust (chrono 0.4.35+)
use chrono::{DateTime, Utc};

let dt: DateTime<Utc> = DateTime::from_timestamp(1_715_429_912, 0).expect("in range");
println!("{}", dt.to_rfc3339());                // 2024-05-11T12:18:32+00:00
println!("{}", dt.format("%Y-%m-%d %H:%M:%S")); // 2024-05-11 12:18:32

let now: i64 = Utc::now().timestamp();           // current Unix seconds
let from_ms = DateTime::from_timestamp_millis(1_715_429_912_000).unwrap();
let parsed = DateTime::parse_from_rfc3339("2024-05-11T12:18:32Z").unwrap();
assert_eq!(parsed.timestamp(), 1_715_429_912);

The output confirms 1715429912 is Saturday, May 11, 2024 at 12:18:32 UTC. Note that DateTime::from_timestamp takes an i64, so negative values (dates before 1970) work: from_timestamp(-86_400, 0) is 1969-12-31 00:00:00 UTC.

Deprecated chrono APIs to migrate away from

Recent chrono 0.4 releases deprecated several older constructors. If you see warnings, migrate them:

For named IANA zones such as Europe/Paris, add the chrono-tz crate and call dt.with_timezone(&chrono_tz::Europe::Paris). chrono by itself only knows Utc, Local, and fixed offsets.

std, chrono, or the time crate?

Use the standard library alone when you only need the current epoch value, for example to stamp a log line, set a cache expiry, or build a JWT exp claim. It adds no dependencies and compiles everywhere. Reach for chrono when you need to format dates for people, parse RFC 3339 or custom strings, or do calendar arithmetic. The time crate (0.3) is a popular alternative with a similar role: OffsetDateTime::from_unix_timestamp(1_715_429_912) returns a Result and formats with its own description syntax. Pick one of the two date crates per project and convert at the boundaries. Mixing them in one module makes timestamps harder to follow in code review.

Common Rust timestamp pitfalls

Coming from Go? The Go timestamp page shows the same conversions with time.Unix. For the history of the epoch itself, see epoch time explained.

Frequently asked questions

How do I get the current Unix timestamp in Rust without crates?

Use SystemTime::now().duration_since(UNIX_EPOCH) and call .as_secs() or .as_millis() on the resulting Duration.

How do I convert a Unix timestamp to a date with chrono?

Call DateTime::from_timestamp(secs, 0), which returns Option<DateTime<Utc>>, then format it with .to_rfc3339() or .format("%Y-%m-%d").

Is NaiveDateTime::from_timestamp_opt deprecated?

Yes, since chrono 0.4.35. Use DateTime::from_timestamp and convert with .naive_utc() only if you need a naive value.

How do I handle milliseconds in Rust?

Use DateTime::from_timestamp_millis(ms) in chrono, or Duration::from_millis with UNIX_EPOCH in the standard library.

How do I use IANA time zones in Rust?

Add the chrono-tz crate and call with_timezone(&chrono_tz::Europe::Paris) on a DateTime<Utc>.

Is my input processed privately?

Yes. The parser and snippets run 100% in your browser; nothing is sent to a server.

Related tools