views:

216

answers:

3

I'm looking for the best*est* way to produce the local time and date in string form, such as, for example:

"2009-09-28-00-44-36.896200000000"

I've been browsing Haskell's Data.Time docs, but I'm a bit stumped. (Big Haskell newbie here.)

Thanks!

+4  A: 

Unless I'm missing what your really after, what you want is:

import Data.Time

getCurrentTime

when run in prelude, you get:

2009-09-28 01:18:27.229165 UTC

or, for local time (as you indicated and I just caught):

getZonedTime

to get:

2009-09-27 20:22:06.715505 CDT
Shaun
+2  A: 
import System.Time

main = do ct <- getClockTime
          print ct

or

import Data.Time

main = do zt <- getZonedTime
          print zt
newacct
+1  A: 

While getCurrentTime and getZonedTime do return the current time and local time respectively, these may not be what liszt is expecting. He wants a string that represents the present time, while both getCurrentTime and getZonedTime returns IO UTCTime and IO ZonedTime respectively

This could do what liszt is looking for:

import Data.Time
currentTime = fmap show getCurrentTime
zonedTime = fmap show getZonedTime

Cheers

sdqali