[Haskell-beginners] get date

Luca Ciciriello luca_ciciriello at hotmail.com
Thu Jun 24 03:52:46 EDT 2010


Just a question.
How can I obtain a String from

currentTime :: IO Day
currentTime =  utctDay `fmap` getCurrentTime

Here currentTime returns to me 2010-06-24, but I want "2010-06-24".
In another worlds I need a function 

currentTimeStr :: IO Day -> String

Any Idea?

Luca.



On Jun 23, 2010, at 8:13 PM, Felipe Lessa wrote:

> On Wed, Jun 23, 2010 at 08:03:16PM +0200, Luca Ciciriello wrote:
>> How can I get the current system date-time in Haskell?
>> 
>> I've used the library Time, but on MacOS X 10.6.4 the year is always 0.
>> 
>> Luca.
> 
> Do you mean, you used getCurrentTime from the time package[1]?
> What does the following line do?
> 
>  (toGregorian . utctDay) `fmap` getCurrentTime
> 
> On my system,
> 
>  GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
>  Loading package ghc-prim ... linking ... done.
>  Loading package integer ... linking ... done.
>  Loading package base ... linking ... done.
>  Prelude> :m Data.Time
>  Prelude Data.Time> (toGregorian . utctDay) `fmap` getCurrentTime
>  Loading package old-locale-1.0.0.1 ... linking ... done.
>  Loading package time-1.1.4 ... linking ... done.
>  (2010,6,23)
> 
> http://hackage.haskell.org/packages/archive/time/1.2.0.3/doc/html/Data-Time-Clock.html#v%3AgetCurrentTime
> 
> HTH,
> 
> --
> Felipe.
> 



More information about the Beginners mailing list