I found the date output script in Russian, but it displays the time not from my computer, where is the error?

function rusdate($d, $format = 'j %MONTH% Y', $offset = 0) { $montharr = array( 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); $dayarr = array( 'понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота', 'воскресенье'); $d += 3600 * $offset; $sarr = array('/%MONTH%/i', '/%DAYWEEK%/i'); $rarr = array( $montharr[date("m", $d) - 1], $dayarr[date("N", $d) - 1] ); $format = preg_replace($sarr, $rarr, $format); return date($format, $d); } 

Call script

 <?php echo rusdate( time(), '%DAYWEEK%, j %MONTH% Y, G:i' ); ?> 

and displays the time for an hour more:

 воскресенье, 15 мая 2016, 10:38 

and I have :

 воскресенье, 15 мая 2016, 9:38 
  • one
    Да, и еще. У функции есть необязательный третий параметр — сдвиг времени. Можно указать кол-во часов, на которые необходимо сдвинуть время относительно часового пояса на сервере. - Visman
  • How is this done? - user33274
  • What does it mean like? I gave you a part of the description that the author gave on his page. You call a function with only two parameters, but you need to call with three, specifying the third difference between the server time zone and yours, probably. - Visman
  • from the fact that I changed the offset to -1, is it? - user33274

1 answer 1

If it's not difficult to look in php.ini or via the phpinfo() function, your time zone is set in the date.timezone directive

 date.timezone = 'Europe/Moscow' 

Does it correspond to the time zone, where are you located? I have your script worked without errors.

  • yes for sure - Europe / Moscow was, thank you, but on a real server, how do you deal with this? - user33274
  • @LenovoID, you can use the function date_default_timezone_set () - cheops
  • Yes, I already read this function, but how on a real server for user N from country Y to calculate? - user33274
  • @LenovoID, you might be interested in the following answer ru.stackoverflow.com/questions/502942 - cheops
  • one
    It can not be, because the time zone for each client is different and you can find it only in the browser, on the server you can get this information only by sending it a request from the browser. Unfortunately, nothing can be done here, the client and server code are spaced apart and separated by runtime. - cheops