I have a website made on word press, on the site a clock that synchronizes with the time on the computer from which it enters the site. That is, the time is set on the site based on the time, the fact that the computer. Purpose: to make the clock on the site displayed regardless of the time of the clock on the computer, and synchronized with the total world time - specifically the city of Yekaterinburg. Is it possible to somehow display a certain time? For example Ekaterinburg. It is necessary to take time according to Just the user does not always have the exact time on the computer, but I wanted to display the exact Yekaterinburg time, despite what time it is from the user who visits my site.

Help me pozh, here is the code that stands on my site. it is between the end of / body inserted. the rules work, only synchronization is done with the total time (Yekaterinburg)

</script> <script type="text/javascript"> function clock() { var d = new Date(); var month_num = d.getMonth() var day = d.getDate(); var hours = d.getHours(); var minutes = d.getMinutes(); var seconds = d.getSeconds(); month=new Array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"); if (day <= 9) day = "0" + day; if (hours <= 9) hours = "0" + hours; if (minutes <= 9) minutes = "0" + minutes; if (seconds <= 9) seconds = "0" + seconds; date_time = "Сегодня - " + day + " " + month[month_num] + " " + d.getFullYear() + " г.&nbsp;&nbsp;&nbsp;"+ hours + ":" + minutes + ":" + seconds; if (document.layers) { document.layers.doc_time.document.write(date_time); document.layers.doc_time.document.close(); } else document.getElementById("doc_time").innerHTML = date_time; setTimeout("clock()", 1000); } </script> <script type="text/javascript"> clock(); </script> 

what in css think not?

    3 answers 3

    To solve your problem, you need to take time from the server of your application (from php), transfer it during Ekaterinburg and display it on the site.

    The client side is not the best time source:

    • time on the client can be shot down

    • The time zone may be incorrect, and the time is correct (if the user's hands are crooked). Then, calculating the time in Ekb from this time and belt, you will get the weather on Mars.

    • help us how to do it To solve your problem, you need to take time from the server of your application (from php), translate it during Ekaterinburg and display it on the site. - user206450
    • how to take time from the server, what to register? where and what code? - user206450
     var d = new Date(); // локальное время пользователя 

    To establish a specific, for example, server, you need to use the syntax:

     var d = new Date(year, month, date, hours, minutes, seconds); 

    how exactly to transfer it to the script depends strongly on the place of the template where this block of code is located. If php injections are supported, it would look like this:

     var d = new Date(<?=date("Y");?>, <?=date("m");?>, <?=date("d");?>, <?=date("H");?>, <?=date("i");?>, <?=date("s");?>); 
    • Comments are not intended for extended discussion; conversation moved to chat . - Nicolas Chabanovsky

    Why so difficult? Install on the WordPress site in adminpanel time of Yekaterinburg. In the right place on the page, ask WordPress this time:

     $time = current_time('dmY H:i:s'); 

    Write to element #doc_time.