I am using chrono. I have now()
and some other NaiveDateTime
. How can I find a difference between them?
let now = Utc::now().naive_utc();
let dt1 = get_my_naive_datetime();
I am using chrono. I have now()
and some other NaiveDateTime
. How can I find a difference between them?
let now = Utc::now().naive_utc();
let dt1 = get_my_naive_datetime();
In more recent versions of chrono
(at least as of 0.4.22, and likely earlier), you can simply subtract NaiveDateTime
s:
println!("{:?}", dt1 - now);
The result is a Duration
, which has methods to convert to whatever units you like, e.g. (dt1 - now).num_days()
.
In older versions of chrono
, you must use NaiveDateTime::signed_duration_since
:
println!("{:?}", dt1.signed_duration_since(now));