How to get timestamp in Rust

There is no need to introduce third-party dependencies, just use the libraries that come with the system.

use std::time::{SystemTime, UNIX_EPOCH};

match SystemTime::now().duration_since(UNIX_EPOCH) {
    Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
    Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}

Think carefully, some people will say that you need the time package or the chrone package. In fact, the official document has a clear answer.

Guess you like

Origin blog.csdn.net/HardRedStone/article/details/122251832