Get Unix / Epoch time as Int

后端 未结 6 1473
日久生厌
日久生厌 2020-12-30 23:44

Is there a function in haskell for epoch time in seconds / milliseconds ?

perhaps something similar to java\'s

System.currentTimeMillis();
         


        
6条回答
  •  独厮守ぢ
    2020-12-31 00:16

    Yes.

    getCurrentTime :: IO UTCTime.

    UNIX epoch time could be retrieved as Int like that:

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

    UPD: as other users noticed, there is much more simple way to do that:

    > :m + Data.Time.Clock.POSIX
    > round `fmap` getPOSIXTime 
    1375040716
    it :: Integer
    

提交回复
热议问题