草庐IT

start_datetime

全部标签

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/

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce

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

ruby-on-rails - 如何从现有的 Time.zone for Rails 创建 Ruby DateTime?

我有用户在RubyonRails网站中输入日期。我将日期解析为DateTime对象,内容如下:date=DateTime.new(params[:year].to_i,params[:month].to_i,params[:day].to_i,params[:hour].to_i,params[:minute].to_i)或date=DateTime.parse(params[:date])两个DateTime都将不在我之前设置的用户时区中,例如:Time.zone="PacificTime(US&Canada)"如何将上述DateTime解析为正确的时区?我知道DateTime.ne

ruby - Ruby 中 DateTime 的毫秒分辨率

我有一个类似2012-01-01T01:02:03.456的字符串,我使用ActiveRecord将其存储在Postgres数据库TIMESTAMP中。不幸的是,Ruby似乎切断了毫秒数:ruby-1.9.3-rc1:078>'2012-12-31T01:01:01.232323+3'.to_datetime=>Mon,31Dec201201:01:01+0300Postgrs支持微秒分辨率。如何相应地保存我的时间戳?我至少需要毫秒分辨率。(PS是的,我可以破解postgres中的毫秒整数列;这违背了ActiveRecord的全部目的。)更新:非常有帮助的回复表明Ruby的DateTi

ruby - 如何在当前类的上下文中运行 IRB.start

我刚看完PragProgContinuousTestingWithRuby,他们讨论了在当前类的上下文中调用IRB以手动检查代码。但是,他们引用说,如果您在类中调用IRB.start,self是预定义的,并且指的是调用start时我们所在的对象这对我来说不是真的。即使是非常简单的例子a="hello"require'irb'ARGV.clear#otherwiseallscriptparametersgetpassedtoIRBIRB.start当我尝试访问a变量时,我得到了明显的结果NameError:undefinedlocalvariableormethod`a'formain:

ruby - 如何从 DateTime 值中删除区域?

我有这个日期时间:=>Fri,03Feb201211:52:42-0500如何删除ruby​​中的区域(-0500)?我只想要这样的东西:=>Fri,03Feb201211:52:42 最佳答案 时间总有一个区(没有区就没有意义)。您可以使用DateTime#strftime在打印时选择忽略它:now=DateTime.nowputsnow#=>2012-02-03T10:01:24-07:00putsnow.strftime('%a,%d%b%Y%H:%M:%S')#=>Fri,03Feb201210:01:24参见Time#st

ruby-on-rails - 我得到 "found character that cannot start any token while scanning for the next token"

我已经在我的笔记本电脑上运行RubyonRails大约一个月了,但是当我想在这个实例中运行服务器时(它在几个小时前工作正常)我现在收到这条消息。请问如何让服务器再次运行?C:\Sites\LaunchPage>railssC:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/psych.rb:203:in`parse':():foundcharacterthatcannotstartanytokenwhilescanningforthenexttokenatline17column17(Psych::SyntaxError)fromC:/RailsIns