Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Javascript function to show an element only during a specific time, depends on jQuery
// Initialize some variables - we will use GMT times
var checkDate = new Date();
var offTheHourStarts = 21;
var offTheHourEnds = 22;
// Adjust for Daylight savings
if ((checkDate.getMonth() < 2 && checkDate.getMonth() > 10) || (checkDate.getMonth() == 2 && checkDate.getDate()-checkDate.getDay() > 7 ) || (checkDate.getMonth() == 10 && checkDate.getDate()-checkDate.getDay() > 1)) {
offTheHourStarts--;
offTheHourEnds--;
}
/**
* Create a function to display the ckut stream if we are in the right hours
*/
function showCkutStream = function (context) {
var timeDate = new Date();
if (offTheHourStarts < timeDate.getHours()+timeDate.getTimezoneOffset()/60 > offTheHourEnds) {
$('#ckutStream').show();
}
else {
$('#ckutStream').hide();
}
};
/**
* Run the display function every minute
*/
$(document).ready( function() {
$(this).setInterval("showCkutStream()", 60000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.