怎么昨天在Haskell?对于当天 - 当然它的工作原理如下:
date :: IO (Integer,Int,Int) -- :: (year,month,day)
date = getCurrentTime >>= return . toGregorian . utctDay
Run Code Online (Sandbox Code Playgroud)
但对于昨天?这适用于diffUTCTime吗?
用sql:
select current date, current date - 1 day from sysdba.routine
08.11.2018 07.11.2018
Run Code Online (Sandbox Code Playgroud)
但是对于Haskell?
您可以使用该addUTCTime :: NominalDiffTime -> UTCTime -> UTCTime功能作为差异-nominalDay.例如:
Prelude Data.Time.Clock> fmap (addUTCTime (-nominalDay)) getCurrentTime
2018-11-07 15:27:57.8510597 UTC
Run Code Online (Sandbox Code Playgroud)
或者当您想要获得格里高利日期时:
Prelude Data.Time.Clock Data.Time.Calendar> fmap (toGregorian . utctDay . addUTCTime (-nominalDay)) getCurrentTime
(2018,11,7)
Run Code Online (Sandbox Code Playgroud)