Format std::time output

You can use the crate chrono to achieve the same result:

extern crate chrono;

use chrono::Local;

fn main() {
    let date = Local::now();
    println!("{}", date.format("%Y-%m-%d][%H:%M:%S"));
}

Edit:

The time crate is not deprecated: it is unmaintained.

Besides, it is not possible to format a time using only the standard library.

Leave a Comment