format date in rust

To format a date in Rust, you can use the format() method and specify the format string. You can use the chrono crate to work with dates and times in Rust.

Here's an example:

main.rs
use chrono::prelude::*;

fn main() {
  let date = Utc::now();
  println!("{}", date.format("%Y-%m-%d %H:%M:%S"));
}
116 chars
7 lines

This code will print the current date and time in the format "YYYY-MM-DD HH:MM:SS". You can customize the format string to display the date and time in other formats.

For more information on formatting dates and times in Rust, you can refer to the chrono crate documentation: https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html

gistlibby LogSnag