gpt4 book ai didi

haskell - 获取 Unix/Epoch 时间为 Int

转载 作者:行者123 更新时间:2023-12-03 10:38:23 27 4
gpt4 key购买 nike

haskell 中是否有以秒/毫秒为单位的纪元时间函数?

也许类似于java的东西

System.currentTimeMillis();

编辑:作为 IntInteger ?

最佳答案

是的。

getCurrentTime :: IO UTCTime .

UNIX 纪元时间可以检索为 Int像那样:

> :m + Data.Time System.Locale Control.Applicative
> epoch_int <- (read <$> formatTime defaultTimeLocale "%s" <$> getCurrentTime) :: IO Int
> epoch_int
1375025861

更新 :正如其他用户所注意到的,有更简单的方法可以做到这一点:
> :m + Data.Time.Clock.POSIX
> round `fmap` getPOSIXTime
1375040716
it :: Integer

关于haskell - 获取 Unix/Epoch 时间为 Int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17909770/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com