Skip to content

Instantly share code, notes, and snippets.

@jdoiwork
Last active May 1, 2017 08:23
Show Gist options
  • Select an option

  • Save jdoiwork/0edfc4475986226e5e3e026522f65696 to your computer and use it in GitHub Desktop.

Select an option

Save jdoiwork/0edfc4475986226e5e3e026522f65696 to your computer and use it in GitHub Desktop.
Haskell parse ISO8601 DateTime
import Data.Time.LocalTime (LocalTime, ZonedTime)
import Data.Time.Clock (UTCTime)
import Data.Time.Format ( parseTimeM
, defaultTimeLocale
, TimeLocale(..)
, ParseTime
)
testTime :: [UTCTime]
testTime = parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%z"
"2017-03-29T11:02:57+00:00 "
testTime2 :: [LocalTime]
testTime2 = parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%z"
"2017-03-29T11:02:57+00:00 "
testTime3 :: [ZonedTime]
testTime3 = parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%z"
"2017-03-29T11:02:57+00:00 "
parseISO8601 :: (Monad m, ParseTime t)
=> String
-> m t
parseISO8601 = parseTimeM True defaultTimeLocale "%Y-%m-%dT%H:%M:%S%z"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment