一.rust获取时间戳
use std::time::{SystemTime, UNIX_EPOCH};
fn get_current_unix() -> u64 {
let unix = SystemTime::now().duration_since(UNIX_EPOCH).expect("get_current_unix_err");
unix.as_secs()
}
使用time包获取时间戳
Cargo.toml

// 精确到秒
fn get_unix()->i64{
time::OffsetDateTime::now_utc().unix_timestamp()
}
// 精确到纳秒
fn get_unix_nano()->i128{
time::OffsetDateTime::now_utc().unix_timestamp_nanos()
}
网友评论