【问题标题】:Convert Ruby DateTime string to Milliseconds [duplicate]将 Ruby DateTime 字符串转换为毫秒 [重复]
【发布时间】:2016-02-15 22:07:37
【问题描述】:

我正在研究如何将以下 Ruby DateTime 转换为毫秒,以便使用 Angular Timer,它看起来使用毫秒作为在“倒计时时间显示中为 countdown 传递的值指定的最大时间单位”示例。

"2016-02-03T16:38:00.000-05:00"

我尝试过使用to_f,如下所示,但不正确:

t = event.actual_end_time
#=> "2016-02-03T16:38:00.000-05:00"
t.to_f * 1000
#=> 2016000.0

【问题讨论】:

    标签: ruby datetime


    【解决方案1】:
    require 'date'
    puts DateTime.now.strftime('%Q')
    

    【讨论】:

      猜你喜欢
      • 2012-08-11
      • 2015-09-14
      • 2023-03-08
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多