如何从UTCTime增加或减去n天?

问题描述

如何从UTCTime库的time类型的值中减去n天?

解决方法

import Data.Time

addDaysUtcTime :: UTCTime -> Integer -> UTCTime
addDaysUtcTime t x = addUTCTime (nominalDay * (fromIntegral x)) t

import Data.Time

addDaysUtcTime :: UTCTime -> Integer -> UTCTime
addDaysUtcTime t x = t { utctDay = (addDays x (utctDay t))}