"ru_RU" setlocale does not work by date and time

I am trying to use Russian with setlocale:

setlocale(LC_TIME,"ru_RUS.utf8"); echo strftime("%A, %B %d", time()); 

Exit: Thursday, August 29th.

Expected: Thursday, August 29

Any help would be greatly appreciated.

+6
source share
3 answers

Found! if you are using linux hosting try:

 setlocale(LC_ALL, 'ru_RU.UTF-8'); 

will work fine. If you are using Windows hosting, try:

 <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> setlocale(LC_ALL, 'russian'); 
+11
source

For the Russian language and UTF-8, you can use this code. Work in Widows and Unix .

 header('Content-type: text/html; charset=utf-8'); $locale_time = setlocale (LC_TIME, 'ru_RU.UTF-8', 'Rus'); function strf_time($format, $timestamp, $locale) { $date_str = strftime($format, $timestamp); if (strpos($locale, '1251') !== false) { return iconv('cp1251', 'utf-8', $date_str); } else { return $date_str; } } echo strf_time("%A, %B %d", time(), $locale_time); 

Result:

 ,  13 
+3
source
 var_dump(setlocale(LC_ALL, 'ru_RU.utf8')); 

The setlocale function returns the result of a system call. I think it should be RU, not Ru.

+2
source

Source: https://habr.com/ru/post/952745/


All Articles