Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert from unixtime to a date/time in Haskell?

Tags:

haskell

So, the setup is that I have the time, in seconds, since the epoch and I want to turn this into a date I can actually understand. How do I do this in Haskell? If it is possible, how would I extract days/hours/minutes out of this new encoding?

like image 330
cornihilio Avatar asked Oct 16 '12 13:10

cornihilio


1 Answers

Data.Time.Clock.POSIX has posixSecondsToUTCTime (you can convert another numeric type to the input expected POSIXTime with realToFrac).

Data.Time.Calendar has a lot of the things you need to extract day, month, etc from the Day that forms a part of UTCTime, the rest of the package has other useful utilities.

Example:

Prelude> import Data.Time.Format.ISO8601
Prelude Data.Time.Format.ISO8601> import Data.Time.Clock.POSIX 
Prelude Data.Time.Format.ISO8601 Data.Time.Clock.POSIX> iso8601Show $ posixSecondsToUTCTime $ 100
"1970-01-01T00:01:40Z"
like image 131
singpolyma Avatar answered Oct 06 '22 00:10

singpolyma