Unix Time On Haskell - 16 Jul 2010
Some languages make it dead simple to get a timestamp or UNIX time as a single integer:
The time() function exists on many languages, others present a Date object and even on
the shell is really easy to get it date +%s.
Is not that hard in Haskell either, it’s just … different.
First, we need to remember that getting the current time is an IO operation, therefore we’ll be
working on the IO Monad.
From the time package we can get a POSIXTime and then use floor to get an Integral:
import Data.Time.Clock.POSIX
main :: IO ()
main = print . floor =<< getPOSIXTimeWhich will print a nice integer as would perl -e 'print time' (not as short but
it get’s the job done)
Comments