7
我正在使用板條箱計時器;經過一番挖掘,我發現DateTime
類型有一個函數timestamp()
,它可以產生i64
類型的紀元時間。但是,我無法找到如何將其轉換回DateTime
。如何將紀元時間轉換爲標準日期和時間?
extern crate chrono;
use chrono::*;
fn main() {
let date = chrono::UTC.ymd(2020, 1, 1).and_hms(0, 0, 0);
println!("{}", start_date.timestamp());
// ...how to convert it back?
}
我設法找到[thisplace]類似的用法(https://docs.rs/ chrono/*/src/chrono/datetime.rs.html#42),但顯然你的答案更簡潔友好。謝謝! – Sajuuk