//First, add the chrono crate to your Cargo.toml: [dependencies] chrono = "0.4" //Then, in your Rust code: use chrono::{NaiveDateTime, TimeZone, Utc}; fn main() { let unix_timestamp: i64 = 1366627714; let naive_datetime = NaiveDateTime::from_timestamp(unix_timestamp, 0); // Convert to UTC let datetime_utc = Utc.from_utc_datetime(&naive_datetime); println!("Converted Date: {}", datetime_utc); }
1366627714
NaiveDateTime
NaiveDateTime::from_timestamp
Utc.from_utc_datetime
2013-04-22 10:48:34
NaiveDateTime::from_timestamp()
NaiveDateTime::from_timestamp(1514764800, 0)
Utc.from_utc_datetime()
Utc.from_utc_datetime(&naive_datetime)
NaiveDate::from_ymd()
NaiveDate
NaiveDate::from_ymd(2018, 7, 15)
NaiveDateTime::and_hms()
date.and_hms(12, 30, 45)
NaiveDateTime::timestamp()
naive_datetime.timestamp()
NaiveDateTime::format()
naive_datetime.format("%Y-%m-%d %H:%M:%S")
Utc::now()
Local::now()