Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created October 2, 2013 12:00
Show Gist options
  • Save qoelet/6792617 to your computer and use it in GitHub Desktop.
Save qoelet/6792617 to your computer and use it in GitHub Desktop.
-- Given a timestamp from a JSON API call
-- Need to convert to Epoch
import Control.Applicative ((<$>))
import Control.Monad (liftM)
import Data.Time
import Data.Time.Clock.POSIX
import System.Locale
main = do
let givenTimeStamp = "2013-09-29 16:36:30"
tsFormat = "%F %T"
tsAsUTCTime = parseTime defaultTimeLocale tsFormat givenTimeStamp :: Maybe UTCTime
tsAsEpoch = (*1000) <$> (utcTimeToPOSIXSeconds `liftM` tsAsUTCTime)
print tsAsEpoch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment