Sort months in Russian

They have the following lines (months in Russian):

" 20 2012" " 19 2012" " 12 2012" " 5 2012" " 2 2012" 

I want to convert them to the following format:

 11.20.2012 12.19.2012 09.12.2012 06.05.2012 08.02.2012 

The problem, of course, is that the month is in Russian, so what I tried does not work.

 $date = " 20 2012"; print_r(date_parse_from_format("F j Y", $date)); 

How can I analyze dates with Russian months?

+4
source share
3 answers

You can do a workaround as follows:

 $ru_month = array( '', '', '', '', '', '', '', '', '', '', '', '' ); $en_month = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); print_r( date_parse_from_format( "F j Y", str_replace( $ru_month, $en_month, $date ) ) ); 

PS: as others claim, there is a direct method, here is a duplicate of your question.

+8
source

tell php first to use your locale settings,

 setlocale( LC_TIME, 'ru_RU', 'russian' ); 

then try to parse the string.

 $date = " 20 2012"; print_r( date_parse_from_format("F j Y", $date) ); 
+3
source

Use setlocale() and strftime() for non-English dates

+1
source

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


All Articles