[![chrono-badge]][chrono] [![cat-date-and-time-badge]][cat-date-and-time]
NaiveDate::from_ymd
和NaiveTime::from_hms
给出一个日期,用NaiveDateTime::timestamp
转换到UNIX 时间戳。然后使用NaiveDateTime::from_timestamp
,它计算从 1970 1,01 0:00:00 UTC 开始,10 亿秒后的日期。
extern crate chrono;
use chrono::{NaiveDate, NaiveDateTime};
fn main() {
let date_time: NaiveDateTime = NaiveDate::from_ymd(2017, 11, 12).and_hms(17, 33, 44);
println!(
"Number of seconds between 1970-01-01 00:00:00 and {} is {}.",
date_time, date_time.timestamp());
let date_time_after_a_billion_seconds = NaiveDateTime::from_timestamp(1_000_000_000, 0);
println!(
"Date after a billion seconds since 1970-01-01 00:00:00 was {}.",
date_time_after_a_billion_seconds);
}