Format std :: time output

I want to display the current time in a specific format.

I am trying to avoid time crate as it is marked as deprecated on the GitHub repository .

I want to use this exact format time::now().strftime("%Y-%m-%d][%H:%M:%S").unwrap()with help std::time, but it doesn’t strftime.

+4
source share
2 answers

There are (currently) two methods now: Instant::nowand SystemTime::now.

Instant He speaks:

Measurement of monotonically increasing hours. Opaque and useful only with Duration.

SystemTime He speaks:

Measuring system clocks useful for communicating with external objects, such as a file system or other processes.

. , - . , , API, .

, chrono, time.

+3

chrono :

extern crate chrono;

use chrono::Local;

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

Edit:

: .

, , .

+6

Source: https://habr.com/ru/post/1651296/


All Articles