rustHow to get current date in Rust
Getting the current date in Rust is easy with the chrono crate.
use chrono::{Local, DateTime};
let now: DateTime<Local> = Local::now();
println!("{}", now);
The code above will print the current date and time in the local timezone.
Code explanation
use chrono::{Local, DateTime};- imports theLocalandDateTimetypes from thechronocratelet now: DateTime<Local> = Local::now();- creates aDateTimeobject with the current date and time in the local timezoneprintln!("{}", now);- prints theDateTimeobject
Helpful links
Related
More of Rust
- Regex example to match multiline string in Rust?
- How to map a Rust slice?
- How to push an element to a Rust slice?
- How to match whitespace with a regex in Rust?
- How to replace strings using Rust regex?
- How to create a HashMap of structs in Rust?
- How to sort a Rust HashMap?
- How to convert a u8 slice to a hex string in Rust?
- How to compile a regex in Rust?
- How to use regex captures in Rust?
See more codes...