R
R
Roman Ismailov2017-10-25 10:40:57
JavaScript
Roman Ismailov, 2017-10-25 10:40:57

How to make several hours on the page of different countries?

There is such a task: to make several clocks of different countries in the landing, I don’t have enough knowledge in JS to understand how I can get the time of each country.
Time still has to tick every minute, but this is not a problem, the problem is getting the correct time for each country. The site will be visited from different cities, and maybe countries, so you need to somehow independently receive each time of the country.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Denis Ineshin, 2017-10-25
@Benny_Lilom

As always, Moment.js comes to the rescue !

R
Roman, 2017-10-25
@r0n1x

var a = new Date().getHours() + new Date().getTimezoneOffset() / 60; // 0 часовой пояс
var b = a + 3; // 3 изменить на нужный часовой пояс
new Date(new Date().setHours(b));

Somehow it turned out scary =)) Rename the b variable to the desired country and set the time zone for it, then substitute it in the last line of the code. Well, then you can get an hour of a minute of a second of a get from it.

M
Mikhail Lyalin, 2017-10-25
@mr_jok

it is easier to display the server time and the time of a specific visitor

A
Andrew, 2017-10-25
@AndrewHaze

Javascript and time zones - correct time on the site

P
pavelblog, 2017-10-25
@pavelblog

We go to Yandex.Time https://yandex.ru/time
We create the necessary widgets
We select "Informer to the site" in the settings
We get a code like this:

<iframe  frameborder="no" scrolling="no" width="150" height="280" src="https://yandex.ru/time/widget/?geoid=10115&lang=ru&layout=vert&type=digital&face=digits"></iframe>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question