我正在处理一个气象硬件中的一些日期时间,它记录到一个.dbf文件。我可以从我正在使用的ruby脚本/web服务器中提取这一点,但我得到的数字如下
41836.532638889
我不确定日期时间是如何表示的,所以很难知道如何解析它。我最好在Ruby中解析它,所以代码将是一个加号,但是如果我知道它是如何表示的,我可以想出如何实现它。
发布于 2014-07-31 03:04:56
该日期是OLE自动化格式的日期,在Excel中很常见。就像谷歌说的
An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24.
对应的Ruby代码是
def self.convert_time(t)
Time.at((t - 25569) * 86400).utc
end减法将时间移至unix时间开始的日期(1970年1月1日)。Unix时间以秒为单位,因此将天转换为秒: 24*60*60=86400。为了方便起见,转换为utc时间。
发布于 2014-07-16 23:17:50
试试Time.at(您的号码/双)。然后,您可以根据需要格式化它。
Time.at(41836.532638889)
=> 1970-01-01 12:37:16 +0100发布于 2014-07-17 14:59:24
41836 -从1899年12月31日起的天数(零日),从所述日期的午夜开始的532638889秒数。
https://stackoverflow.com/questions/24792383
复制相似问题