简体   繁体   English

如何比较两个UTCTime值并获得天数差异?

[英]How to compare two UTCTime values and get the difference in days?

I want to take away from UTCTime - UTCTime.我想从 UTCTime - UTCTime 中删除。 I found the following function:我发现了以下功能:

diffUTCTime :: UTCTime -> UTCTime -> NominalDiffTime

But I get the difference in NominalDiffTime , and I need to get the difference in days但是我得到了NominalDiffTime的差异,我需要得到天数的差异

Is there any function for this?有什么功能吗?

Something other than nominalDiffTimeToSeconds ?!除了nominalDiffTimeToSeconds其他东西?!

NominalDiffTime is, among others, a Fractional , so you can divide your result with nominalDay : NominalDiffTime是除其他外的Fractional ,因此您可以将结果与nominalDay

Prelude Data.Time.Clock> myDiffTime / nominalDay
2.314814814814s

You can use its RealFrac instance to round , floor , etc. it:您可以使用它的RealFrac实例来roundfloor等。它:

Prelude Data.Time.Clock> round $ myDiffTime / nominalDay
2
Prelude Data.Time.Clock> truncate $ myDiffTime / nominalDay
2
Prelude Data.Time.Clock> floor $ myDiffTime / nominalDay
2
Prelude Data.Time.Clock> ceiling $ myDiffTime / nominalDay
3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM