Cthulhu
Cthulhu

Reputation: 739

How to get date in haskell?

I'm working with Haskell and I would like to get the year of the current date in haskell. I want the output to be an Int or String. Thanks.

Upvotes: 3

Views: 3991

Answers (1)

Gabriel L.
Gabriel L.

Reputation: 1709

From https://wiki.haskell.org/Getting_the_current_date:

import Data.Time.Clock
import Data.Time.Calendar

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

If you only want the year…

year :: IO Integer
year = (\(y, _, _) -> y) <$> date

Upvotes: 12

Related Questions