php - Get month name in Symfony -
is possible somehow name of given month (by number) in symfony's controller. , in current locale.
form's date widget translates month current locale automatically. same in controller.
i know how country translated didn't found same funtionality month.
thanks
solution doesn't rely on symfony components (except locale):
setlocale(lc_all, $this->request->getlocale()); $month = strftime("%b", mktime(0, 0, 0, $monthid, 1, 2000));
first, take @ official icu docs date formatting. icu underlying component intl
(mentioned yann in comments above).
so, given variable $monthid
contains number of month, do:
$monthid = .... $date = new \datetime(); # overwrite date first day in month $y = (int)$date->format('y'); $date->setdate($y, $monthid, 1); # create formatter $fmt = new intldateformatter( 'en_us', // locale? "llll", // <--- long month format intldateformatter::full, 'america/los_angeles', // time zone, not important in case intldateformatter::gregorian ); # format month $monthname = $fmt->format($date);
hope helps...
Comments
Post a Comment