Crates/Chrono
12 articles
How to Add and Subtract Time in Rust
Add and subtract time in Rust by using standard arithmetic operators on numeric duration values.
How to Calculate Duration Between Two Times in Rust
Calculate the time difference in Rust by subtracting two `Instant` values to get a `Duration`.
How to Format Dates and Times in Rust
Format dates and times in Rust using the chrono crate and format strings.
How to Get the Current Date and Time in Rust
Use the `chrono` crate to get the current date and time, as the standard library's `std::time::SystemTime` lacks convenient formatting and calendar methods.
How to Parse Date Strings in Rust
Convert Rust strings to numbers using the .parse() method and handle errors with match or expect.
How to Serialize and Deserialize Dates with Serde in Rust
Serialize and deserialize Rust dates with Serde by using the chrono crate and specific attribute annotations like ts_utc or iso8601.
How to use chrono crate in Rust date and time
The `chrono` crate provides the `NaiveDateTime` and `DateTime` types for handling dates and times, with `DateTime<Tz>` being the standard choice for timezone-aware operations.
How to Use the chrono Crate in Rust
The `chrono` crate provides a robust set of date and time types, with `NaiveDateTime` for timezone-agnostic calculations and `DateTime` for timezone-aware operations.
How to Use the time Crate in Rust
Use the `time` crate for modern, type-safe timestamp handling by leveraging its `OffsetDateTime` type for local time and `PrimitiveDateTime` for UTC, then format or parse strings using the `format_description` module.
How to Use Timestamps (Unix Epoch) in Rust
Get the current Unix epoch timestamp in seconds or milliseconds using std::time::SystemTime and UNIX_EPOCH.
How to Work with Time Zones in Rust
Use the chrono crate to parse timestamps and convert between UTC and local time zones in Rust.
What Is the Difference Between chrono and the time Crate?
chrono is the legacy date-time library, while time is the modern, faster, and safer alternative for new Rust projects.