-
Notifications
You must be signed in to change notification settings - Fork 374
Formatting dates
kosta edited this page Nov 25, 2012
·
7 revisions
Add old-locale to .cabal.
import Data.Time
import System.Locale (defaultTimeLocale)
dateFormat = "%e %b %Y"
dateFormat :: String
dateTimeFormat = "%e %b %Y %H:%M:%S"
dateTimeFormat :: String
formatDateStr :: String -> String
formatDateStr dateString = formatTime defaultTimeLocale dateTimeFormat t
where
t = read dateString
t :: UTCTime
main = print $ formatDateStr "2012-09-15 00:07:31.874712 UTC"
Useful when you use a Day field and jQuery date picker.
import Data.Time
import System.Locale (defaultTimeLocale)
dateFormat = "%e %b %Y"
dateFormat :: String
dateTimeFormat = "%e %b %Y %H:%M:%S"
dateTimeFormat :: String
formatDay :: Day -> String
formatDay day = formatTime defaultTimeLocale dateFormat t
where
t = UTCTime day 0
t :: UTCTime
main = do
now <- getCurrentTime
let today = utctDay now
print $ formatDay today