开发者

DateTime formatting Rails

开发者 https://www.devze.com 2023-01-07 11:44 出处:网络
I have \"Date.today + 2.days\" I need to format it using .strftime, but with the \"+2.days\" it doesn\'t recogni开发者_StackOverflow中文版ze that method.Any ideas?Those nice helpers don\'t come with a

I have "Date.today + 2.days" I need to format it using .strftime, but with the "+2.days" it doesn't recogni开发者_StackOverflow中文版ze that method.Any ideas?


Those nice helpers don't come with a vanilla ruby install. You need the activesupport gem (part of Ruby on Rails).

$ gem install activesupport

$ irb
ruby-1.8.7-p249 > require 'rubygems'
 => true 
ruby-1.8.7-p249 > require 'active_support'
 => true 
ruby-1.8.7-p249 > Date.today
 => Fri, 16 Jul 2010 
ruby-1.8.7-p249 > Date.today + 2.days
 => Sun, 18 Jul 2010 


I don't see a problem, worked fine for me.

(Date.today + 2.days).strftime
#=> "2010-07-18"
0

精彩评论

暂无评论...
验证码 换一张
取 消