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
- How to replace strings using Rust regex?
- How to get struct length in Rust
- How to use regex to match a double quote in Rust?
- How to do a for loop with index in Rust
- How to match whitespace with a regex in Rust?
- How to match a URL with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to replace all matches using Rust regex?
- How to use non-capturing groups in Rust regex?
- Regex example to match multiline string in Rust?
See more codes...