Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试找到将天数添加到 Chrono 的首选方法UTC。我想将 137 天添加到当前时间:
UTC
let dt = UTC::now();
只需使用Duration适当的运算符:
Duration
use chrono::{Duration, Utc}; fn main() { let dt = Utc::now() + Duration::days(137); println!("today date + 137 days {}", dt); }
在操场上测试。
我只是想改进@Stargateur 的答案。不需要使用timecrate,因为chronocrateDuration里面有 struct:
time
chrono
extern crate chrono; use chrono::{Duration, Utc}; fn main() { let dt = Utc::now() + Duration::days(137); println!("{}", dt); }
操场上的另一个测试