如果我不使用 rails,我如何在 ruby 中使用 Time.zone 我想做 Time.now,但这在 rails 中可用,但在 ruby 中不可用
我以为
require 'time'
会解决这个问题并使其在 ruby 中可用,但它没有,我明白了
NoMethodError: undefined method `zone' for Time:Class
最佳答案
我不知道,你是什么意思。但我认为它应该如下工作:
(arup~>~)$ pry --simple-prompt
>> Time.now
=> 2014-04-09 23:19:04 +0530
>> Time.now.strftime('%Z')
=> "IST"
>> Time.now.strftime('%z')
=> "+0530"
>> Time.now.zone
=> "IST"
关于ruby - 无方法错误 : undefined method `zone' for Time:Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22970157/