datetime format - Haskell: File Access Time Formatted "yyyy-MM-dd" -


i'm getting quite lost in different date , time libraries available me in haskell. i'm trying format file modification time "yyyy-mm-dd". can show me how that?

i've got code-snippet:

main =   times <- mapm getmodificationtime $ datafiles config -- datafiles returns [filepath].   -- i'd following:   (putstr . unlines . map formatdate) times 

this i've attempted. please don't laugh!

formatdate t =   let (year, month, day) = togregorian $ utctday t    in intercalate "-" $ map show [year, fromintegral month, fromintegral day] 

i know it's not specifications yet, because won't months , days left-filled zero. can fix that. figure there's more elegant way i'm after, why i've titled post i'm after rather current error i'm getting, which, sake of completeness couldn't match expected type 'utctime' actual type 'clocktime'.

thanks whatever can give or clarity can provide.

something should convert clocktime utctime:

import system.time import data.time.clock.posix  utctimefromclocktime :: clocktime -> utctime utctimefromclocktime (tod seconds picoseconds)    = posixsecondstoutctime . fromrational         $ frominteger seconds + frominteger picoseconds / 1000000000000 

you want convert use local time zone. use utctolocalzonedtime :: utctime -> io zonedtime data.time.localtime.

either way, have timestamp can format:

import data.time.format import system.locale  formatisodate :: formattime t => t -> string formatisodate = formattime defaulttimelocale "%f" 

(sorry, i've not tested of code.)


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -