简体   繁体   English

Ruby on Rails-从参数构建时间

[英]Ruby on Rails - Build time from params

I've this following params: 我有以下参数:

 {"utf8"=>"✓",
 "authenticity_token"=>"sPoWmnLU984Py9BEIe8MgEVo8tqPsSdLznFZ0dITXAw=",
 "event"=>{"title"=>"",
 "description"=>"",
 "day"=>"2013-11-21",
 "start(1i)"=>"2013",
 "start(2i)"=>"11",
 "start(3i)"=>"25",
 "start(4i)"=>"07",
 "start(5i)"=>"00",
 "end(1i)"=>"2013",
 "end(2i)"=>"11",
 "end(3i)"=>"25",
 "end(4i)"=>"07",
 "end(5i)"=>"00",
 "day_id"=>"day"},
 "commit"=>"Event erstellen"}

and my controller: 和我的控制器:

start  = "#{params[:event][:start(4i)]}:#{params[:event][:start(5i)]}"

I want only the times attributes from the parameters, so that at the end i have something like this: 我只想从参数中获取times属性,以便最后我可以看到以下内容:

07:00

If "start" is a DateTime attribute of the model, you could simply use the strftime method of the dateTime. 如果“ start”是模型的DateTime属性,则可以简单地使用dateTime的strftime方法。 Something like start.strftime("%H:%M") 类似于start.strftime(“%H:%M”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM