I've tried googling about but struggling to find a concrete example or which libraries I should be using for this.
I'd like to format a value of type NominalDiffTime
(NominalDiffTime) for example as 05/10/2017 10:10AM
.
Figured it out. I think there is some confusion because of the type alias: type POSIXTime = NominalDiffTime
(https://hackage.haskell.org/package/time-1.8.0.3/docs/Data-Time-Clock-POSIX.html#t:POSIXTime).
import Data.Time.Clock
import Data.Time.Format
import Data.Time.Clock.POSIX
myFormatUtcTime :: UTCTime -> String
myFormatUtcTime = formatTime defaultTimeLocale "%H:%M %d/%m/%Y"
myFormatDiffTime :: NominalDiffTime -> String
myFormatDiffTime = formatTime defaultTimeLocale "%H:%M" . posixSecondsToUTCTime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With