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转换为字符串类型,怎么做?
答案 0 :(得分:1)
使用posixSecondsToUTCTime
也在Data.Time.Clock.POSIX中将POSIXTime
转换为UTCTime
;然后从Data.Time.Format formatTime
将UTCTime
格式化为String
。
e.g。
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。)