gpt4 book ai didi

ruby - 如何将这种时间格式转换为 Ruby 中的 unix 时间戳?

转载 作者:太空宇宙 更新时间:2023-11-03 16:20:59 25 4
gpt4 key购买 nike

时间以这种格式给出 t=2015-10-01 23:10:11。我尝试使用以下代码,但它会引发错误:Time.parse(t).to_i。那么,我该如何转换呢?

最佳答案

您的代码有效。你忘记了 require 'time'

require 'time'
t="2015-10-01 23:10:11"
Time.parse(t).to_i
# => 1443766211

顺便说一句,请随时发布错误。否则我们必须猜测问题出在哪里。

关于ruby - 如何将这种时间格式转换为 Ruby 中的 unix 时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33374294/

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