Skip to main content

Greetings. 

I have found some great articles on this topic here but I am having an issue with my timezone and the UTC setting on my Unbounce page.

I want these elements to only show during the PST timezone no matter where the viewer is around the world. 

Here is the code I have so far but I can’t get it to work.  None of my elements switch no matter what time. 

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

<script>  
var d = new Date();
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = new Date(utc + (3600000*offset));
var CurrentDay = nd.getUTCDay();
var BusinessHours = nd.getUTCHours();
  
console.log(nd);
if (CurrentDay != 0 && CurrentDay < 6 && BusinessHours >= 7 || BusinessHours <= 16) { 
             $("#lp-pom-box-409").hide();
             $("#lp-pom-text-341").hide();
             $("#lp-pom-text-461").show();
            $("#lp-pom-button-460").show();
            $("#lp-pom-button-209").hide(); 


       } else {
                $("#lp-pom-box-409").show();
                 $("#lp-pom-text-341").show();
                 $("#lp-pom-text-461").hide();
                $("#lp-pom-button-460").hide();
                $("#lp-pom-button-209").show();
       };
</script> 

 

Suggestions?  Thanks to everyone who posts here.  It has been so helpful but now I am a bit stuck. 

Greetings. 
Wanted to leave this here in case anyone else is trying to do this. 
I think I figured this out and ended up with this code.  If anyone has suggestions, I am open. 

<script type="text/javascript">
  
var d = new Date();
var localTime = d.getTime(); 
var localOffset = d.getTimezoneOffset() * 60000; 
var utc = localTime + localOffset;
var offset = 7;  
var PST = utc - (3600000*offset);
var nd = new Date(PST);  
var CurrentDay = nd.getDay();
var BusinessHours = nd.getHours();
  
console.log(nd); 
if(CurrentDay != 0 && CurrentDay < 6 && BusinessHours >= 16 || BusinessHours <= 7){ 
             $("#lp-pom-box-409").hide();
             $("#lp-pom-text-341").hide();
             $("#lp-pom-text-461").show();
            $("#lp-pom-button-460").show();
            $("#lp-pom-button-209").hide(); 


    } else {
               $("#lp-pom-box-409").show();
                 $("#lp-pom-text-341").show();
                 $("#lp-pom-text-461").hide();
                $("#lp-pom-button-460").hide();
                $("#lp-pom-button-209").show();

};
    
</script>


Reply