There is a timer of several dates on JS and there is a check where the current time is compared with the given one:

var timeEnds = [ new Date(date.getFullYear(), 6 - 1, 12, 23, 00), // new Date(год, месяц - 1, день, час, минуты); new Date(date.getFullYear(), 6 - 1, 13, 5, 00), new Date(date.getFullYear(), 6 - 1, 13, 19, 30), new Date(date.getFullYear(), 6 - 1, 13, 21, 30), new Date(date.getFullYear(), 6 - 1, 13, 23, 00), new Date(date.getFullYear(), 6 - 1, 14, 4, 00), new Date(date.getFullYear(), 6 - 1, 14, 19, 00), new Date(date.getFullYear() + 1, 6 - 1, 12, 23, 00) ]; ... var timeIndex = 0; // Индекс массива с датами var nowdate = new Date(); // Текущее время for (var i = 0; i < timeEnds.length; i++) { // Цикл по массиву дат if (nowdate > timeEnds[timeIndex]) { // Проверка на наступление даты из массива timeIndex++; // Переходим к следующей дате } else { break; } } 

The fact is that the current time of the user installed on the PC is compared. That is, the time zone is not taken into account or the situation when the user does not have the correct date at all. How to solve this problem, maybe there are some libraries or a site that can parse?

1 answer 1

Total independent time is unixtime. Unixtime will be the same for the United States, and for the Russian Federation and for any other country. This is the number of seconds since midnight (UTC) on January 1, 1970. In javascript it can be obtained as follows:

 parseInt(new Date().getTime()/1000); 

Just initially work with unixtime.

  • The answer is not related to the author's problem in any way. - Duck Learns to Take Cover
  • does not solve the problem when the user doesn’t have the correct date at all - Grundy