javascript: change the countdown timer from the local time to the specific time zone

The code we are currently showing is:

This is showing a countdown timer. But it is based on a specific time based on the location of the users.

Instead, we want to show a difficult date at 3 pm Pacific Time (PST). So that no matter where you are in the world, the countdown shows the same amount.

The js code is the following.

$ (function ()

{
var countDownClock =
{
iniClock: function (date)
{
// calculating days, hours, minutes and seconds to date.
date = date.split (& # 39;: & # 39;);
toDate = new Date (date[0], date[1]-1, date[2], date[3], date[4], date[5]);

                                var currentDate = new Date ();
dateDif = toDate - currentDate;
daysCount = (& # 39; 0000 & # 39; + Math.abs (Math.floor ((dateDif) / (1000 * 60 * 60 * 24)))). slice (-4),
hoursCount = (& # 39; 00 & # 39; + Math.abs (Math.floor (date[3] - currentDate.getHours ()))) slice (-2),
minuteCount = (& # 39; 00 & # 39; + Math.abs (Math.floor (date[4]-currentDate.getMinutes ()))). slice (-2),
secondCount = (& # 39; 00 & # 39; + Math.abs (Math.floor (date[5]-currentDate.getSeconds ()))). slice (-2),
ticksCount = Math.round (dateDif / 1000);

yes[3] - currentDate.getHours () <0)
{
hoursCount = (& # 39; 00 & # 39; + (24 - parseInt (hoursCount))) slice (-2);
}
yes[4] - currentDate.getMinutes () <0)
{
hoursCount = (& # 39; 00 & # 39; + (parseInt (hoursCount) - 1)) slice (-2);
minuteCount = (& # 39; 00 & # 39; + (60 - parseInt (minuteCount))) slice (-2);
yes (hoursAccount <0)
{
hoursCount = (& # 39; 00 & # 39; + (24 + parseInt (hoursCount))) slice (-2);
}

}
yes[5] - currentDate.getSeconds () <0)
{
minuteCount = (& # 39; 00 & # 39; + (parseInt (minuteCount - 1))) slice (-2);
secondCount = (& # 39; 00 & # 39; + (60 - parseInt (secondCount))) slice (-2);
yes (minuteCount <0)
{
hoursCount = (& # 39; 00 & # 39; + (parseInt (hoursCount) - 1)) slice (-2);
minuteCount = (& # 39; 00 & # 39; + (60 + parseInt (minuteCount))) slice (-2);
}
yes (hoursAccount <0)
{
hoursCount = (& # 39; 00 & # 39; + (24 + parseInt (hoursCount))) slice (-2);
}
}

var second = secondCount.charAt (1),
tenSecond = secondCount.charAt (0),
minute = minuteCount.charAt (1),
tenMinute = minuteCount.charAt (0),
hour = hoursCount.charAt (1),
tenHour = hoursCount.charAt (0),
day = daysCount.charAt (3),
tenDay = daysCount.charAt (2),
hunDay = daysCount.charAt (1),
thosDay = daysCount.charAt (0),
secondBefore = second - 1,
tenSecondBefore = tenSecond - 1,
minuteBefore = minute - 1,
tenMinuteBefore = tenMinute - 1,
hourBefore = hour - 1,
tenHourBefore = tenHour - 1,
dayBefore = day - 1,
tenDayBefore = tenDay - 1,
hunDayBefore = hunDay - 1,
thosDayBefore = thosDay - 1,
container = $ (& # 39;
& # 39;), dayContainer = $ (& # 39;
& # 39;), thosDayBlk = $ (& # 39;
    & # 39;), hunDayBlk = $ (& # 39;
      & # 39;), tenDayBlk = $ (& # 39;
        & # 39;), dayBlk = $ (& # 39;
          & # 39;), tenHourBlk = $ (& # 39;
            & # 39;), hourBlk = $ (& # 39;
              & # 39;) tenMinuteBlk = $ (& # 39;
                & # 39;), minuteBlk = $ (& # 39;
                  & # 39;) tenSecondBlk = $ (& # 39;
                    & # 39;), secondBlk = $ (& # 39;
                      & # 39;), itemTmp = & # 39;
                    • {{num}}
                      {{num}}
                    • & # 39 ;; yes (dateDif <0) { second = tenSecond = minute = tenMinute = hour = tenHour = day = tenDay = hunDay = thos = 0; } yes (second <= 0) secondBefore = 9; yes (ten seconds <= 0) tenSecondBefore = 5; yes (minute <= 0) minuteBefore = 9; yes (tenMinute <= 0) tenMinuteBefore = 5; yes (time <= 0) hourBefore = 5; yes (tenHour <= 0) tenHourBefore = 2; yes (day <= 0) dayBefore = 9; if (tenDay <= 0) tenDayBefore = 9; yes (hunDay <= 0) hunDayBefore = 9; yes (thosDay <= 0) thosDayBefore = 9; // building the html structure $ (& # 39 ;. countDownClock & # 39;). append (container); dayContainer.prependTo (container) .append (dayBlk) .append (tenDayBlk) .append (hunDayBlk) .append (thosDayBlk); for (var i = 0, flip = dayContainer.find (& # 39 ;. flip & # 39;); i < flip.length; i++) { var curFlip = flip.eq(i); for (var j = 9; j >= 0; j--) { curFlip.append (Mustache.to_html (itemTmp, {num: j})); } } container.append (tenHourBlk); for (var j = 2; j> = 0; j--) { tenHourBlk.append (Mustache.to_html (itemTmp, {num: j})); } container.append (hourBlk); for (var j = 9; j> = 0; j--) { hourBlk.append (Mustache.to_html (itemTmp, {num: j})); } for (var j = 3; j> = 0; j--) { hourBlk.append (Mustache.to_html (itemTmp, {num: j})); } container.append (tenMinuteBlk); for (var j = 5; j> = 0; j--) { tenMinuteBlk.append (Mustache.to_html (itemTmp, {num: j})); } container.append (minuteBlk); for (var j = 9; j> = 0; j--) { minuteBlk.append (Mustache.to_html (itemTmp, {num: j})); } container.append (tenSecondBlk); for (var j = 5; j> = 0; j--) { tenSecondBlk.append (Mustache.to_html (itemTmp, {num: j})); } container.append (secondBlk); for (var j = 9; j> = 0; j--) { secondBlk.append (Mustache.to_html (itemTmp, {num: j})); } // adjustment timer $ (& # 39;. CountDownClock .flip.secondPlay li: nth-child (& # 39; + (10 - secondBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.secondPlay li: nth-child (& # 39; + (10 - second) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.tensecondPlay li: nth-child (& # 39; + (6 - tenSecondBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.tensecondPlay li: nth-child (& # 39; + (6 - tenSecond) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.minutePlay li: nth-child (& # 39; + (10 - minuteBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.minutePlay li: nth-child (& # 39; + (10 - minute) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.tenminutePlay li: nth-child (& # 39; + (6 - tenMinuteBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.tenminutePlay li: nth-child (& # 39; + (6 - tenMinute) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.hourPlay li: nth-child (& # 39; + (10 - hourBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.hourPlay li: nth-child (& # 39; + (10 - hour) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.tenhourPlay li: nth-child (& # 39; + (3 - tenHourBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.tenhourPlay li: nth-child (& # 39; + (3 - tenHour) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.dayPlay li: nth-child (& # 39; + (10 - dayBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.dayPlay li: nth-child (& # 39; + (10 - day) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.tendayPlay li: nth-child (& # 39; + (10 - tenDayBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.tendayPlay li: nth-child (& # 39; + (10 - tenDay) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.hundayPlay li: nth-child (& # 39; + (10 - hunDayBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.hundayPlay li: nth-child (& # 39; + (10 - hunDay) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); $ (& # 39;. CountDownClock .flip.thosdayPlay li: nth-child (& # 39; + (10 - thosDayBefore) + & # 39;) & # 39;). addClass (& # 39; pre-before & # 39;); $ (& # 39;. CountDownClock .flip.thosdayPlay li: nth-child (& # 39; + (10 - thosDay) + & # 39;) & # 39;). addClass (& # 39; pre-active & # 39;); // hide days-blk yes 0 if (thosDay == 0) { container.css ( & # 39; width & # 39 ;, container.width () - dayBlk.width () - (parseInt (dayBlk.css (& # 39; margin & # 39;)) * 2) ); thosDayBlk.hide (); } if (hunDay == 0 && thosDay == 0) { container.css ( & # 39; width & # 39 ;, container.width () - dayBlk.width () - (parseInt (dayBlk.css (& # 39; margin & # 39;)) * 2) ); hunDayBlk.hide (); } if (tenDay == 0 && thosDay == 0 && hunDay == 0) { container.css ( & # 39; width & # 39 ;, container.width () - dayBlk.width () - (parseInt (dayBlk.css (& # 39; margin & # 39;)) * 2) ); tenDayBlk.hide (); } if (day == 0 && thosDay == 0 && hunDay == 0 && tenDay == 0) { container.css ( & # 39; width & # 39 ;, container.width () - dayBlk.width () - (parseInt (dayBlk.css (& # 39; margin & # 39;)) * 2) ); dayBlk.hide (); dayContainer.hide (); } yes (dateDif> 0) { clockTick = setInterval (function () { ticksCount--; if (ticksCount> = 0) countDownClock.countChange (secondBlk); plus { if ($ (& # 39;. countDownClock .secondPlay .active .inn & # 39;). html ()! = & # 39; 0 & # 39;) countDownClock.countChange (secondBlk); plus clearInterval (clockTick); } }, 1000); } } countChange: function (flip) { $ ("body"). removeClass ("play"); var aa = flip.find (& # 39; li.active & # 39;) if (aa.html () == undefined) { aa = flip.find ("li.pre-active"); aa.removeClass (& # 39; pre-active & # 39;); flip.find ("li.pre-before"). removeClass (& # 39; pre-before & # 39;); } if (aa.parent (). hasClass (& # 39; hourPlay & # 39;) && aa.is (": nth-child (10)")) { var bb = flip.prev (). find (& # 39; li.active & # 39;); if (bb.html () == not defined) bb = flip.prev (). find (& # 39; li.pre-active & # 39;); $ (". countDownClock ul.hourPlay li"). removeClass ("before"); aa.addClass ("before"). removeClass ("active"); if (bb.is (": last-child")) { aa = $ (". countDownClock ul.hourPlay li"). eq (10); } plus { aa = $ (". countDownClock ul.hourPlay li"). eq (0); } aa.addClass ("active") .closest ("body") .addClass ("play"); // some shit to find prev-clock-block prevFlip = flip.prev (); if (! prevFlip.hasClass (& # 39; flip & # 39;) && prevFlip.length> 0) prevFlip = prevFlip.prev (& # 39; & # 39;); if (prevFlip.length> 0) countDownClock.countChange (prevFlip); } else if (aa.is (": last-child")) { flip.find (& # 39; li & # 39;). removeClass ("before"); aa.addClass ("before"). removeClass ("active"); aa = flip.find ("li"). eq (0); aa.addClass ("active") .closest ("body") .addClass ("play"); // some shit to find prev-clock-block if (flip.hasClass (& # 39; days & # 39;)) { prevFlip = flip.next (); } plus { prevFlip = flip.prev (); if (prevFlip.hasClass (& # 39; day-container & # 39;)) { prevFlip = prevFlip.find (& # 39 ;. flip.dayPlay & # 39;); } } if (prevFlip.length> 0) countDownClock.countChange (prevFlip); } plus { flip.find (& # 39; li & # 39;). removeClass ("before"); aa.addClass ("before") .removeClass ("active") next ("li") .addClass ("active") .closest ("body") .addClass ("play"); } } } countDownClock.iniClock ($ (& # 39 ;. countDownClock & # 39;). attr (& # 39; data-to-date & # 39;)); // YYYY: MM: DD: hh: mm: ss

});