Reputation: 1024
Right now I have the date displayed in the format mm/dd/yyyy by using <h6><%= Time.now.strftime("%m/%d/%Y") %></h6>
but I want the day of week as well. Preferably it would display like: Wednesday, October 2. Thanks
Upvotes: 0
Views: 422
Reputation: 118289
Using pure ruby class Date
and Time
require 'time'
require 'date'
t = Time.now
t.wday # => 3
Date::ABBR_DAYNAMES[t.wday]
# => "Wed"
Date::DAYNAMES[t.wday]
# => "Wednesday"
Upvotes: 1
Reputation: 3615
Say i have date = Time.now.to_date then date.strftime("%A") will print name for the day of the week and to have just the number for the day of the week write date.wday.
Copy from here
So Time.now.strftime("%A")
and in your case
<h6>
<%= Time.now.strftime("%A, %B %d. %Y") %>
</h6>
Easiest to test this is the rails c
. To remove the leading zero on the %d
use %-d
instead.
Upvotes: 2
Reputation:
You should be able to get the full weekday name with %A (i.e. Sunday) and the abbreviated weekday name with %a (i.e. Sun).
Upvotes: 1