user12163
user12163

Reputation:

How to produce a local datetime string in Haskell?

I want to produce the local time and date in string form, such as, for example:

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

Upvotes: 10

Views: 5084

Answers (3)

Shaun
Shaun

Reputation: 4008

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

import Data.Time

getCurrentTime

when run in GHCi, 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

Upvotes: 11

sdqali
sdqali

Reputation: 2234

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

Upvotes: 6

newacct
newacct

Reputation: 122419

import System.Time

main = do ct <- getClockTime
          print ct

or

import Data.Time

main = do zt <- getZonedTime
          print zt

Upvotes: 2

Related Questions