Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name of this month (Date.today.month as name)

Tags:

ruby

People also ask

How to get full month name in php?

$monthName = date('F', mktime(0, 0, 0, $monthNumber, 10));

How to display date with month name in php?

php $date = "2019-11-11"; echo "Displaying date... \n"; echo "Date = $date"; $month_name = date("F", mktime(0, 0, 0, 11, 10)); echo "\nMonth = ".

How do you write month names in Python?

To get the month name from a number in Python, the easiest way is with strftime() and passing “%M”. You can also use the calendar module and the month_name() function.


Date::MONTHNAMES[Date.today.month] would give you "January". (You may need to require 'date' first).


You can also use I18n:

I18n.t("date.month_names") # [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
I18n.t("date.abbr_month_names") # [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
I18n.t("date.month_names")[Date.today.month] # "December"
I18n.t("date.abbr_month_names")[Date.today.month] # "Dec"

You can use strftime:

Date.today.strftime("%B") # -> November

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#strftime-method


If you care about the locale, you should do this:

I18n.l(Time.current, format: "%B")

For Ruby 1.9 I had to use:

Time.now.strftime("%B")