10

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

"2009-09-28-00-44-36.896200000000"
Michał Perłakowski
93.3k30 gold badges165 silver badges189 bronze badges
asked Sep 27, 2009 at 22:48

3 Answers 3

11

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
SwiftsNamesake
1,5782 gold badges12 silver badges26 bronze badges
answered Sep 28, 2009 at 1:19
Sign up to request clarification or add additional context in comments.

Comments

6

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

answered Aug 28, 2010 at 20:53

Comments

2
import System.Time
main = do ct <- getClockTime
 print ct

or

import Data.Time
main = do zt <- getZonedTime
 print zt
answered Sep 28, 2009 at 1:24

1 Comment

Why not main = print =<< getClockTime?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.