Answer the question
In order to leave comments, you need to log in
Why is the correct time returned only when called again?
I caught a very strange situation when moving from debian to centos to another server ..
In the view there is a time output like this:
var_dump(HtmlPurifier::process(NewTime::new_time(strtotime('2018-06-15 13:26:27'))));
var_dump(HtmlPurifier::process(NewTime::new_time(strtotime('2018-06-15 13:26:27'))));
<?php
namespace app\models;
class NewTime{
public static function new_time($a) { // преобразовываем время в нормальный вид
date_default_timezone_set('Europe/Moscow');
$ndate = date('d.m.Y', $a);
$ndate_time = date('H:i', $a);
$ndate_exp = explode('.', $ndate);
$nmonth = array(
1 => 'января',
2 => 'февраля',
3 => 'марта',
4 => 'апреля',
5 => 'мая',
6 => 'июня',
7 => 'июля',
8 => 'августа',
9 => 'сентября',
10 => 'октября',
11 => 'ноября',
12 => 'декабря'
);
foreach ($nmonth as $key => $value) {
if($key == intval($ndate_exp[1])) $nmonth_name = $value;
}
if($ndate == date('d.m.Y')) return 'сегодня в '.$ndate_time;
elseif($ndate == date('d.m.Y', strtotime('-1 day'))) return 'вчера в '.$ndate_time;
else return $ndate_exp[0].' '.$nmonth_name.' '.$ndate_exp[2].' в '.$ndate_time;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question