简体   繁体   English

怎么昨天在Haskell?当前日期 - 1天?

[英]How get yesterday in Haskell? Current date - 1 day?

How get yesterday in Haskell? 怎么昨天在Haskell? For the current day - of course it works like this: 对于当天 - 当然它的工作原理如下:

date :: IO (Integer,Int,Int) -- :: (year,month,day)
date = getCurrentTime >>= return . toGregorian . utctDay

But for yesterday? 但对于昨天? Does that work with diffUTCTime? 这适用于diffUTCTime吗?

With sql: 用sql:

select current date, current date - 1 day from sysdba.routine 
08.11.2018 07.11.2018

But with Haskell? 但是对于Haskell?

You can use the addUTCTime :: NominalDiffTime -> UTCTime -> UTCTime function with as difference -nominalDay . 您可以使用addUTCTime :: NominalDiffTime -> UTCTime -> UTCTime函数,区别为-nominalDay For example: 例如:

Prelude Data.Time.Clock> fmap (addUTCTime (-nominalDay)) getCurrentTime
2018-11-07 15:27:57.8510597 UTC

or when you want to obtain the Gregorian date: 或者当您想要获得格里高利日期时:

Prelude Data.Time.Clock Data.Time.Calendar> fmap (toGregorian . utctDay . addUTCTime (-nominalDay)) getCurrentTime
(2018,11,7) 

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

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