jjzjj

datetime-format

全部标签

ruby - DateTime.strptime 我做错了什么?

当我这样做时,我的ruby​​程序说我的日期无效:format="%D/%M/%Y%H:%M:%S:3N"date="21/03/201116:39:11.642"DateTime.strptime(time,format)这个我也试过:format="%D/%M/%Y%H:%M:%S:3"我得到的是这个:ArgumentError:invaliddatefrom/usr/local/lib/ruby/1.9.1/date.rb:1688:in`new_by_frags'from/usr/local/lib/ruby/1.9.1/date.rb:1713:in`strptime'fro

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby - 你如何让 DateTime.parse 返回你所在时区的时间?

我需要这个require'date'DateTime.parse"Mon,Dec276:30pm"返回EDT时区下午6:30的DateTime,但返回UTC时间。如何获取EST日期时间或将UTC日期时间转换为具有下午6:30值的EDT日期时间? 最佳答案 好的,我要回答我自己的问题require'time'ENV["TZ"]="US/Eastern"Time.parse("Mon,Dec276:30pm").to_datetime=># 关于ruby-你如何让DateTime.parse

ruby-on-rails - 移至生产服务器的 Rails 应用出现 "dump format error for symbol"错误

我刚刚将我的Rails应用程序从开发服务器转移到部署服务器。我已经安装了passenger,但我想尝试使用railss来确保一切正常(这是我第一次开发和部署rails应用程序)。规范是:Ruby1.9.3和RVM、mod_passenger、Rails3.2.3。全部安装正确,我还启用了Apache模块。顺便说一句,出了点问题(乘客一直在说“错误信息:未知key:类(class)”。)运行railss会出现上面列出的奇怪错误dumpformaterrorforsymbol(0x45)ProcessingbyDevise::SessionsController#newasHTMLRend

ruby - minitest 可以做类似 "rspec --color --format doc"的事情吗?

我想要一份关于正在运行的测试的打印精美的摘要,类似于rspec--color--formatdoc可以minitest这样做吗? 最佳答案 "HowtocolorunittestswithlibminitestorTest:Unit?是一个类似的问题。那里提供了几个选项:骄傲turnpurdytestminitest-reporters 关于ruby-minitest可以做类似"rspec--color--formatdoc"的事情吗?,我们在StackOverflow上找到一个类似的问

ruby-on-rails - 将 ActiveSupport::TimeWithZone 转换为 DateTime

我试图在两个日期之间每隔N天步进一次。我尝试了以下代码,但没有用,因为startDate和endDate是ActiveSupport::TimeWithZone对象,而不是我想的DateTime对象。startDate.step(endDate,step=7){|d|putsd.to_s}min.step(max,step=stepInt){|d|putsd.to_s}如何将TimeWithZone对象转换为DateTime? 最佳答案 我认为更新这个答案可能会有用,因为我最近在搜索这个。实现此转换的最简单方法是使用.to_date

ruby-on-rails - 从 Ruby 中的 DateTime 变量获取时间

我在ruby​​工作,我有一个包含数据库中今天日期时间的对象。我只想要时间截断数据。我怎样才能得到它? 最佳答案 尝试DateTime#strftime.DateTime.now.strftime("%H:%M")#=>"12:17" 关于ruby-on-rails-从Ruby中的DateTime变量获取时间,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/12562804/

ruby-on-rails - Rails link_to :format => :xlsx not generating link to . xlsx 路径

如果我点击这个url:http://localhost:3000/reports/action.xlsx它会显示生成的xlsx文件。如果我有这样的link_to::xlsx%>它生成一个链接到这个页面:http://localhost:3000/reports/action为什么我使用:format=>:xlsx的link_to没有链接到正确的路径? 最佳答案 您的link_to和path略有偏差。你要格式是path助手的参数,而不是link_to。 关于ruby-on-rails-Ra

ruby-on-rails - RoR,无法从 DateTime/TimeWithZone 迭代

我有一个简单的任务,我想获取一个开始日期和一个结束日期,然后循环计算天数/日期。这段代码正在我的db:seedrake任务中使用。目前,我的代码经历了以下尝试。(someModel.start_date.to_datetime..someModel.end_date.to_datetime).each{|x|putsx}......(someModel.start_date...someModel.end_date).each{|x|putsx}在每种情况下,我都会收到这样的错误。can'titeratefromActiveSupport::TimeWithZoneorcan'tite

ruby-on-rails - 如何在 Ruby 中更改 DateTime 的时区?

在保持时区不变的情况下读取、写入和序列化日期和时间变得很烦人。我正在使用Ruby(和Rails3.0)并试图改变DateTime的时区。(到UTC)但不是时间本身。我想要这个:t=DateTime.nowt.hour->4t.offset=0t.hour->4t.utc?->true我最接近的是这个,但它不直观。t=DateTime.nowt.hour->4t+=t.offsett=t.utct.hour->4t.utc?->true有没有更好的办法? 最佳答案 使用Rails3,您正在寻找DateTime.change()dt=D