The strftime docs http://www.ruby-doc.org/stdlib-2.1.1/libdoc/date/rdoc/Date.html#method-i-strftime声称%Q
works:
%Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.
但它为我返回“%Q”。
2.1.1 :054 > date = Time.now
=> 2014-06-10 12:28:57 -0700
2.1.1 :055 > date.strftime("%Q")
=> "%Q"
我正在使用 RVM 和 Ruby 2.1.1。
是我做错了什么,还是这是 Ruby 的 bug?
其他答案提到了如何使用 DateTime 执行此操作,但如果您更喜欢使用 Time 对象(例如因为Rubocop 的默认设置抱怨使用 DateTime.now https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/DateTime),那么这等价:
Time.now.strftime("%s%L")
%s
自纪元以来的秒数,并且%L
是当前秒的毫秒数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)