Buscar..


Sintaxis

  • addDays :: Integer -> Day -> Day

  • diffDays :: Day -> Day -> Integer

  • fromGregorian :: Integer -> Int -> Int -> Day

     convert from proleptic Gregorian calendar. First argument is year, second month number (1-12), third day (1-31). Invalid values will be clipped to the correct range, month first, then day.
    
  • getCurrentTime :: IO UTCTime

Observaciones

El módulo Data.Time del paquete de time proporciona soporte para recuperar y manipular valores de fecha y hora:

Encontrar la fecha de hoy

La fecha y la hora actuales se pueden encontrar con getCurrentTime :

import Data.Time

print =<< getCurrentTime
-- 2016-08-02 12:05:08.937169 UTC

Alternativamente, fromGregorian devuelve solo la fecha:

fromGregorian 1984 11 17  -- yields a Day

Sumando, restando y comparando días

Dado un Day , podemos realizar comparaciones aritméticas simples, como agregar:

import Data.Time

addDays 1 (fromGregorian 2000 1 1)
-- 2000-01-02
addDays 1 (fromGregorian 2000 12 31)
-- 2001-01-01

Sustraer:

addDays (-1) (fromGregorian 2000 1 1)
-- 1999-12-31

addDays (-1) (fromGregorian 0 1 1)
-- -0001-12-31
-- wat

e incluso encontrar la diferencia:

diffDays (fromGregorian 2000 12 31) (fromGregorian 2000 1 1)
365

Tenga en cuenta que el orden importa:

diffDays (fromGregorian 2000 1 1) (fromGregorian 2000 12 31)
-365


Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow