gpt4 book ai didi

ruby - 如何将 FILETIME 转换为 Ruby 时间,反之亦然

转载 作者:数据小太阳 更新时间:2023-10-29 08:43:01 28 4
gpt4 key购买 nike

MSDN 将 FILETIME 定义为

64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

如何在 FILETIME 和 Ruby Time 之间转换?

最佳答案

class Time
# Convert the time to the FILETIME format, a 64-bit value representing the
# number of 100-nanosecond intervals since January 1, 1601 (UTC).
def wtime
self.to_i * 10000000 + (self.tv_nsec/100.0).round + 116444736000000000
end

# Create a time object from the FILETIME format, a 64-bit value representing
# the number of 100-nanosecond intervals since January 1, 1601 (UTC).
def self.from_wtime(wtime)
Time.at((wtime - 116444736000000000) / 10000000,
((wtime - 116444736000000000) % 10000000)/10.0)
end
end

来源:Christopher Sexton ,我修复了纳秒/100 精度。

用法:

wtime = 131172192735329876
#=> 131172192735329876

t = Time.from_wtime(wtime)
#=> 2016-09-01 12:01:13 -0400

t.wtime
#=> 131172192735329876

t.wtime == wtime
#=> true

Time.now.wtime
#=> 131520319622603520

关于ruby - 如何将 FILETIME 转换为 Ruby 时间,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46648714/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com