将刻度解析为日期时间 [英] Parse ticks to datetime
本文介绍了将刻度解析为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Ruby 中将刻度(例如 1298011537289
)转换为 DateTime?
How can I convert a tick, such as 1298011537289
to a DateTime in Ruby?
我需要转换的值来自 JavaScript Date.now()
调用,所以它以毫秒为单位
The value I need to convert is coming from a JavaScript Date.now()
call, so it's in milliseconds
推荐答案
根据 Ruby 文档:
myTime = Time.at(1298011537289)
或者因为您使用的是毫秒而不是秒:
or since you're using milliseconds rather than seconds:
myTime = Time.at(1298011537289 / 1000)
但这只会删除亚秒级精度,以保留它:
But that will only remove sub-second precision, to retain it:
myTime = Time.at(Rational(1298011537289, 1000))
这篇关于将刻度解析为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文