Haskell:将UTCTime转换为秒和毫秒 [英] Haskell : Convert UTCTime to seconds and milliseconds
本文介绍了Haskell:将UTCTime转换为秒和毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我也很好地使用包含年,月等等的n元组,直到毫秒(或我想过使用 show
,然后解析 String code> value,但我相信有更方便的东西。解析方法
重新解析一个字符串非常不合Haskellish ,你当然不想要。
我会用 Data.Time.LocalTime
,
todSec。 localTimeOfDay。 utcToLocalTime utc
可以以秒为单位分辨皮秒。
In other words, I'm looking for the equivalent of Python's datetime.utcnow().
I'm also fine with a n-tuple containing years, months and so on, up until milliseconds (or microseconds).
I had thought of using show
and then parsing the String
value, but I believe there's something more convenient.
解决方案
Re-parsing a string is very un-Haskellish, you certainly don't want that.
I'd use, from Data.Time.LocalTime
,
todSec . localTimeOfDay . utcToLocalTime utc
that gives you seconds in picosecond-resolution.
这篇关于Haskell:将UTCTime转换为秒和毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文