N
N
nepster-web2014-03-18 15:26:06
PHP
nepster-web, 2014-03-18 15:26:06

How to implement the output of months in Russian in the standard php DateTime class?

$this->DateTime = new DateTime();
...
return $this->DateTime->format('Y-m-d H:i:s');

Tell me, please, how can I bring this date format Ymd H: i: s
into something like this: January 1, 2014 at 15:30

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Khirenko, 2014-03-18
@nepster-web

Brings exactly your format to the form January 1, 2014 15:30.

function getRusDate($datetime) {
    $yy = (int) substr($datetime,0,4);
    $mm = (int) substr($datetime,5,2);
    $dd = (int) substr($datetime,8,2);
    
    $hours = substr($datetime,11,5);
    
    $month =  array ('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
    
    return ($dd > 0 ? $dd . " " : '') . $month[$mm - 1]." ".$yy." г. " . $hours;
  }

1
1001001 111, 2014-03-18
@IgorO2

I suggest using a regular expression =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question