[Haskell-beginners] OI UTCTime to String

David McBride toad3k at gmail.com
Thu Nov 10 19:23:36 UTC 2016


It looks like you are trying to get time in UTC, then figuring out what
date it is?  You should be able to get the answer you are looking for with

getFormattedDate = do
  utc <- getCurrentTime
  return $ formatTime defaultTimeLocale "%m/%d/%Y" utc

Just keep in mind that that is the date in UTC.  Not in your local time
zone and it ignores daylight savings time.  To get it in your time you'll
have to replace getCurrentTime with getZonedTime.

On Thu, Nov 10, 2016 at 1:44 PM, sasa bogicevic <brutallesale at gmail.com>
wrote:

> Hi All,
>
> This is a small program
>
> {-# LANGUAGE OverloadedStrings #-}
> module Main where
>
> import           Control.Monad.IO.Class     (liftIO)
> import qualified Data.ByteString.Lazy.Char8 as L
> import           Data.Time
> import           Network                    (withSocketsDo)
> import           Network.HTTP.Conduit
>
>
> createRequestData today = [("index:brKursneListe",""),
>  ("index:year","2016"),
>  ("index:inputCalendar1", today),
>  ("index:vrsta","3"),
>  ("index:prikaz","0"),
>  ("index:buttonShow","Prikazi")]
>
>
> timeFromString  s = parseTimeOrError True defaultTimeLocale "%d %b %Y
> %l:%M %p" s
>
> formatDateString time = formatTime defaultTimeLocale "%m/%d/%Y" time
>
> getDateString = getCurrentTime
>
> getFormatedDate  = formatDateString $ timeFromString getDateString
>
> main = do
>         print $ getFormatedDate
>
>
> And here is my error
>
> main.hs:25:54: error:
>    • Couldn't match type ‘IO UTCTime’ with ‘[Char]’
>      Expected type: String
>        Actual type: IO UTCTime
>    • In the first argument of ‘timeFromString’, namely ‘getDateString’
>      In the second argument of ‘($)’, namely
>        ‘timeFromString getDateString’
>      In the expression: formatDateString $ timeFromString getDateString
>
> Thanks!
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161110/c74c57d4/attachment.html>


More information about the Beginners mailing list