1
Prelude> import Data.Time.Clock.POSIX (getPOSIXTime)
Prelude Data.Time.Clock.POSIX> ptime <- getPOSIXTime
Prelude Data.Time.Clock.POSIX> ptime
1360059876.245525s
Prelude Data.Time.Clock.POSIX> :t ptime
ptime :: Data.Time.Clock.POSIX.POSIXTime
Prelude Data.Time.Clock.POSIX> 

我想将 ptime 转换为字符串类型,怎么做?

4

1 回答 1

1

posixSecondsToUTCTime在 Data.Time.Clock.POSIX 中也使用将 转换POSIXTimeUTCTime; 然后formatTime从 Data.Time.Format 将其格式化UTCTimeString.

例如

formatTime defaultTimeLocale "%FT%T" (posixSecondsToUTCTime ptime)
-- ^ ISO 8601
formatTime defaultTimeLocale "%s%Qs" (posixSecondsToUTCTime ptime)
-- ^ fractional seconds since the epoch (but see caveat noted in documentation)

defaultTimeLocale来自 System.Locale。)

于 2013-02-05T10:32:39.060 回答