The have the following lines (the months are 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've tried doesn't work.
$date = "Ноябрь 20 2012";
print_r(date_parse_from_format("F j Y", $date));
How can I parse dates with Russian months?
You can do a workaround like this:
$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 stated, there is a direct method, here is a duplicate of your question.
first tell php 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) );
Use setlocale()
and strftime()
for non-english dates
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