How to show current year in view?
Is there a function I can use to show the current year in a view? I have tried
<%= Time.now %>
to try and show the time but this does not work for me.
Solution 1:
<%= Time.current.year %>
http://pleac.sourceforge.net/pleac_ruby/datesandtimes.html
Solution 2:
I'd rather use Date class to get year than Time class (if you only need the Date, you don't need to consider hours, minutes and seconds).
<%= Date.today.year %>
c.f. http://ruby-doc.org/stdlib-2.1.0/libdoc/date/rdoc/Date.html#method-c-today
Solution 3:
I think the best way to get the current year considering application timezone is:
Date.current.year