Here's an example:Alternative to using "read", if you know date format of input-data, you can take a look at "UNIX-style parsing" section at Data.Time.Format module [1]. If you have older "time" package, you'd probably use parseTime, for newer versions it is recommended to use parseTimeM.Hi Dananji!First of all, for more explicit failure-handling I suggest using "readMay" from package "safe" [0] instead of "read" whenever possible.
```
➜ ~ ghci
GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help
Prelude> import Data.Time.Format
Prelude Data.Time.Format> import System.Locale
Prelude Data.Time.Format System.Locale> import Data.Time.Clock
Prelude Data.Time.Format System.Locale Data.Time.Clock> parseTime defaultTimeLocale "%F %X" "2014-01-02 11:12:30" :: Maybe UTCTime
Just 2014-01-02 11:12:30 UTC
```If you have a value of type "IO <something>", you can "extract" it when being in IO monad like this:main = docurrentTime <- getCurrentTime-- in all remaining code, currentTime has type "UTCTime"
...getDifference currentTime userTimeIn terms of "sugar-less" way to use a value from "IO <something>", you can also use it like this:getCurrentTime >>= \currentTime -> doSomething currentTimeHope this helps.On Thu, May 14, 2015 at 10:20 AM, Dananji Liyanage <dan9131@gmail.com> wrote:_______________________________________________Hi All,I'm trying out the date time conversions in Haskell.How do I convert a keyboard input (IO String) to UTCTime?This is how I'm doing (probably there's a better way),convDay x = read (x ++ " 00:00:00") :: UTCTimeAnother thing, how do I convert getCurrentTime (IO UTCTime) to UTCTime in order to get the time difference between the keyboard input date and today?--Regards,
Dananji Liyanage
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners