草庐IT

list_of_dates

全部标签

ruby - Date.today 是 UTC 吗?

在Ruby中调用Date.today返回当前日期。但是,它在哪个时区?我假设是UTC,但我想确定一下。documentation没有说明任何一种方式。 最佳答案 你可以使用Time.now.utc.to_dateruby 关于ruby-Date.today是UTC吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/10219670/

ruby - Date、Time 和 DateTime 类是否必需?

Date和Time类可以同时处理这两个类的目的是什么? 最佳答案 总结一下常见的ruby​​时间类是什么:时间这是基本的主力核心ruby​​时间类。具有日期和时间属性(年、月、日、时、分、秒、亚秒)基于unix纪元(1970-01-01)的浮点秒间隔可以处理unix纪元之前的负数可以处理以秒为单位的时间运算在本地使用UTC或“本地”(系统时区)在处理时区时确实有3种Time对象,让我们看一个夏令时来显示DST:utc=Time.utc(2012,6,1)#=>2012-12-2100:00:00UTCutc.zone#=>"UTC"

Ruby:将 Date 和 Time 对象组合成 DateTime

简单的问题,但我找不到好的或明确的答案。将Ruby日期和时间对象(对象,而不是字符串)组合成单个DateTime对象的最佳和最有效的方法是什么? 最佳答案 我找到了这个,但它并不像你希望的那样优雅:d=Date.new(2012,8,29)t=Time.nowdt=DateTime.new(d.year,d.month,d.day,t.hour,t.min,t.sec,t.zone)顺便说一句,rubyTime对象还存储年、月和日,因此您在创建DateTime时会丢弃它。 关于Ruby:

ruby-on-rails - 为什么 Ruby on Rails 使用 http ://0. 0.0.0 :3000 instead of http://localhost:3000?

当我尝试按照官方“入门”RubyonRails教程进行操作时,很快就出错了。基本上它说:…navigatetohttp://localhost:3000.YoushouldseeRails’defaultinformationpage.但是当我按照说明操作时,我得到了=>Rails2.3.4applicationstartingonhttp://0.0.0.0:3000在尝试了这两个地址之后,我知道它们指向同一件事,但是有人可以向我解释为什么RubyonRails使用http://0.0.0.0:3000而不是http://localhost:3000?有没有办法让WEBrick服务器

ruby-on-rails - 测试 : how to focus on behavior instead of implementation without losing speed?

似乎有两种完全不同的测试方法,我想引用它们。问题是,这些意见是在5年前(2007年)提出的,我很感兴趣,从那以后发生了什么变化,我应该走哪条路。BrandonKeepers:Thetheoryisthattestsaresupposedtobeagnosticoftheimplementation.Thisleadstolessbrittletestsandactuallyteststheoutcome(orbehavior).WithRSpec,Ifeellikethecommonapproachofcompletelymockingyourmodelstotestyourcontr

ruby-on-rails - 类型错误 : no implicit conversion of Symbol into Integer

我在尝试更改散列的值时遇到了一个奇怪的问题。我有以下设置:myHash={company_name:"MyCompany",street:"Mainstreet",postcode:"1234",city:"MyCity",free_seats:"3"}defcleanupstringstring.titleizeenddefformatoutput=Hash.newmyHash.eachdo|item|item[:company_name]=cleanup(item[:company_name])item[:street]=cleanup(item[:street])output当我

ruby-on-rails - Ruby 1.87 与 1.92 Date.parse

在Ruby1.87中我可以这样做:Date.parse("3/21/2011")现在在1.9.2中我得到:ArgumentError:invaliddate有什么想法吗? 最佳答案 使用strptime并给出特定的时间格式。ruby-1.9.2-p136:022>Date.strptime'03/21/2011','%m/%d/%Y'=>#参见michaelmichael'sresponseRuby版本之间存在这种差异的原因。 关于ruby-on-rails-Ruby1.87与1.92D

ruby - 强制 bundle 安装使用 https ://instead of git://for GitHub-based gems

我正在尝试构建一个Rails项目,因为我正在使用的主机无法访问Internet的git://协议(protocol)(端口9418),我收到如下错误Fetchinggit://github.com/pivotal/jasmine.gitfatal:unabletoconnecttogithub.com:github.com[0:192.30.252.130]:errno=Connectionrefused运行bundleinstall时。GemFile中的相关行没有指定git://作为协议(protocol),它只是指向GitHub作为gem的源gem'jasmine',:github

ruby - 警告 : Can't verify CSRF token authenticity in case of API development

我现在正在使用RubyonRails开发网络API。当Rails应用程序收到没有任何csrftoken的POST请求时,将出现以下错误消息。因为该应用没有View。WARNING:Can'tverifyCSRFtokenauthenticity所以我的问题是在这种情况下如何安全地逃避csrftoken检查?非常感谢您。 最佳答案 你可以通过添加skip_before_filter:verify_authenticity_token到你的Controller。这样,所有传入Controller的请求都会跳过:verify_authen

ruby - 为什么Ruby 的Date 类会自动加载而DateTime 不会?

为什么使用IRB会自动加载Date&Time类,但DateTime类不会?我必须require'date',这对我来说没有意义,因为我认为Date和DateTime都在使用标准库'date'?ruby-1.9.2-p290:001>Date=>Dateruby-1.9.2-p290:002>Time=>Timeruby-1.9.2-p290:003>DateTimeNameError:uninitializedconstantObject::DateTimefrom(irb):3from/Users/kamilski81/.rvm/rubies/ruby-1.9.2-p290/bin/