N
N
Nikita Galkin2014-10-07 19:01:01
PHP
Nikita Galkin, 2014-10-07 19:01:01

How to use date_create with Russian dates in php?

Here is the code

$test = setlocale(LC_TIME, "Russian");
var_dump($test);
$test = date_create('06 окт. 2014 21:45:17');
var_dump($test);

Issues:
string(19) "Russian_Russia.1251"
bool(false)

That is, the Russian locale is set, but date recognition does not come out of the string. Tell me what to do? The option of replacing the names of months with English variants is obvious, but somehow unpleasant.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2014-10-07
@galk_in

$dateFormatter = new \IntlDateFormatter(
    'ru',
    \IntlDateFormatter::FULL,
    \IntlDateFormatter::FULL,
    new \DateTimeZone('UTC'),
    IntlDateFormatter::GREGORIAN,
    'dd MMM yyyy HH:mm:ss'

);

$string = '06 окт. 2014 21:45:17';
var_dump($string);
$timestamp = $dateFormatter->parse($string);
$test = new \DateTime(sprintf('@%s UTC', $timestamp));
var_dump($test);

php.net/manual/en/book.intl.php
Format: userguide.icu-project.org/formatparse/datetime

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question