如何在Haskell中获得昨天?对于当天-当然,它的工作方式如下:
date :: IO (Integer,Int,Int) -- :: (year,month,day)
date = getCurrentTime >>= return . toGregorian . utctDay
但是昨天呢? diffUTCTime可以使用吗?
使用sql:
select current date, current date - 1 day from sysdba.routine
08.11.2018 07.11.2018
但是有Haskell吗?
答案 0 :(得分:6)
您可以将addUTCTime :: NominalDiffTime -> UTCTime -> UTCTime
函数与-nominalDay
区别对待。例如:
Prelude Data.Time.Clock> fmap (addUTCTime (-nominalDay)) getCurrentTime
2018-11-07 15:27:57.8510597 UTC
或当您想要获取公历日期时:
Prelude Data.Time.Clock Data.Time.Calendar> fmap (toGregorian . utctDay . addUTCTime (-nominalDay)) getCurrentTime
(2018,11,7)