Skip to content

Instantly share code, notes, and snippets.

@mitchmccline
Last active March 25, 2025 13:53
Show Gist options
  • Save mitchmccline/92dc51c0ff2406b062a65290709f280d to your computer and use it in GitHub Desktop.
Save mitchmccline/92dc51c0ff2406b062a65290709f280d to your computer and use it in GitHub Desktop.
Schedule visibility element start and end date/time
<div id="targetElem">Content</div>
<script>
(function() {
const targetElement = document.getElementById('targetElem');
targetElement.style.display = 'none'; //hide element initially
const scheduledStartDate = new Date('2025-04-02T23:59:00-04:00'); //dateTime needs to be in EDT/EST
const startDate = new Intl.DateTimeFormat('en-US', {timeZone: 'America/New_York',hour12: false, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'}).format(scheduledStartDate);
const scheduledEndDate = new Date('2025-04-06T23:59:00-04:00'); //dateTime needs to be in EDT/EST
const endDate = new Intl.DateTimeFormat('en-US', {timeZone: 'America/New_York',hour12: false, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'}).format(scheduledEndDate);
const now = new Date();
const estNow = new Intl.DateTimeFormat('en-US', {timeZone: 'America/New_York', hour12: false, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'}).format(now);
if (estNow >= startDate && estNow <= endDate) {
targetElement.style.display = 'none'; //hide element
} else {
targetElement.style.display = 'block';//show element
}
//console.log('estNow: ' + estNow)
//console.log('startDate: ' + startDate)
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment