I have a date object in Rails, which I'd like to format.
I've made it this far:
delivery_time.date.strftime("%w, %d/%m/%Y")
I'd like it to print out 'Wednesday, 04/01/2012'
Is there a quick method to change the '%w' into 'Wednesday'?
Javascript date getDay() method returns the day of the week for the specified date according to local time. The value returned by getDay() is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.
To get the first day of the current week, get the day of the month, subtract the day of the week and add 1 to consider Monday the first day of the week. Copied!
Getting the day name from a date: function getDayName(dateStr, locale) { var date = new Date(dateStr); return date. toLocaleDateString(locale, { weekday: 'long' }); } var dateStr = '05/23/2014'; var day = getDayName(dateStr, "nl-NL"); // Gives back 'Vrijdag' which is Dutch for Friday.
Looking at the Ruby docs for strftime
Time.now.strftime("%A, %d/%m/%Y")
=> "Wednesday, 04/01/2012"
The %A
character is the full day name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With