Skip to content

Instantly share code, notes, and snippets.

@jaseemabid
Created October 30, 2015 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaseemabid/0bbf7ab2e0eac6c2ecaa to your computer and use it in GitHub Desktop.
Save jaseemabid/0bbf7ab2e0eac6c2ecaa to your computer and use it in GitHub Desktop.
Get current time as an integer
-- Definitely not the best way to get current time as integer
currentPosixTime <- (getCurrentTime >>= return . utcTimeToPOSIXSeconds)
let currentTime = (round (read (init $ show(currentPosixTime)) :: Float) :: Integer)
@joehillen
Copy link

FWIW, if you think you ever need to call read on the result of show, you can be certain you're on the wrong track.

@jaseemabid
Copy link
Author

@joehillen Of course I knew I was wrong, but hoogle didn't give me a UTCTime -> Int or POSIXTime -> Int and this had to be done quick.

@jaseemabid
Copy link
Author

@joehillen Thanks for the links.

@jaseemabid
Copy link
Author

@joehillen seems like an exceptionally large package for the job. I might have to copy required functions verbatim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment