如何找到 2 NaiveDateTimes 之间的差异? [英] How to find the difference between 2 NaiveDateTimes?
本文介绍了如何找到 2 NaiveDateTimes 之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 chrono.我有 now()
和其他一些 NaiveDateTime
.我怎样才能找到它们之间的区别?
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();
推荐答案
使用NaiveDateTime::signed_duration_since
:
println!("{:?}", dt1.signed_duration_since(now))
(游乐场)
它返回一个 Duration
,它有 &self
的方法来产生你喜欢的任何单位,例如dt1.signed_duration_since(now).num_days()
.
It returns a Duration
, which has &self
-taking methods to yield whatever units you like, e.g. dt1.signed_duration_since(now).num_days()
.
这篇关于如何找到 2 NaiveDateTimes 之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文