获得时间作为Int [英] get time as Int
本文介绍了获得时间作为Int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能类似于java的
System.currentTimeMillis();
edit:as Int
或 Integer
?
解决方案
是。
getCurrentTime :: IO UTCTime
。
UNIX纪元时间可以检索为 Int
like that:
> :m + Data.Time System.Locale Control.Applicative
> epoch_int< - (读取< $> formatTime defaultTimeLocale%s< $> getCurrentTime):: IO Int
> epoch_int
1375025861
UPD :其他用户注意到更简单的方法是:
> :m + Data.Time.Clock.POSIX
> round`fmap` getPOSIXTime
1375040716
it :: Integer
Is there a function in haskell for epoch time in seconds / milliseconds ?
perhaps something similar to java's
System.currentTimeMillis();
edit: as Int
or Integer
?
解决方案
Yes.
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
这篇关于获得时间作为Int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文