rustHow to format dates and times in Rust?
Rust has a library called chrono which provides functions for formatting dates and times.
The following example shows how to format a date and time using chrono:
use chrono::{DateTime, Utc};
fn main() {
// Create a DateTime object
let dt = Utc::now();
println!("Current date and time: {}", dt);
// Format the DateTime object
let formatted_dt = dt.format("%Y-%m-%d %H:%M:%S").to_string();
println!("Formatted date and time: {}", formatted_dt);
}
The output of the above code would be:
Current date and time: 2020-11-09 11:55:06.874117 UTC
Formatted date and time: 2020-11-09 11:55:06
More of Rust
- How to convert a Rust HashMap to a BTreeMap?
- How to replace all matches using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use regex to match a group in Rust?
- How to get a capture group using Rust regex?
- How to use regex to match a double quote in Rust?
- How to use a tuple as a key in a Rust HashMap?
- How to parse JSON string in Rust?
- How to use regex with bytes in Rust?
- How to calculate the inverse of a matrix in Rust?
See more codes...