SystemTime and chrono
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 Real-world use cases for Rust
- Tagging observability metrics with the current epoch second in a Rust service.
- Deserializing JSON API timestamps into DateTime<Utc> for timezone-safe processing.
- Comparing expiry timestamps on cached tokens without pulling in a heavyweight date library.
| Unix timestamp (seconds) | ISO 8601 (UTC) |
|---|---|
| 0 | 1970-01-01T00:00:00.000Z |
| 946,684,800 | 2000-01-01T00:00:00.000Z |
| 1,754,136,000 | 2025-08-02T12:00:00.000Z |
| 2,147,483,647 | 2038-01-19T03:14:07.000Z |
| 2,524,608,000 | 2050-01-01T00:00:00.000Z |
These are the same fixed timestamps used in the Rust examples above — every conversion returns one of these values.
Frequently asked questions
How do I get the current Unix timestamp in Rust?
Use SystemTime::now().duration_since(UNIX_EPOCH) then .as_secs() for seconds. It returns a Result because of the theoretical pre-1970 clock case; in practice unwrap() is safe.
How do I convert an epoch timestamp to a date in Rust?
With the chrono crate, DateTime::<Utc>::from_timestamp(1754136000, 0) builds a UTC datetime. Call .to_rfc3339() for an ISO 8601 string or .with_timezone(&tz) for a specific timezone.
Should I use the standard library or chrono for timestamps in Rust?
The standard library covers reading the current time via SystemTime. For formatting, timezone conversion and parsing you almost always want chrono or time — they are the de-facto standards in the Rust ecosystem.
Epoch to human date in Rust
Try it live — convert any timestamp in Rust-friendly format.
Seconds or milliseconds — the unit is auto-detected. Example: 1735689600
UTC ISO 8601
–
Local — auto
–
RFC 2822 / GMT
–
Seconds value
–
Relative time
–
Other programming languages
Copy-paste epoch conversion snippets in your favorite stack
More timestamp guides
Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.