Skip to content

Instantly share code, notes, and snippets.

@ingozoell
Last active December 27, 2015 08:09
Show Gist options
  • Save ingozoell/7294202 to your computer and use it in GitHub Desktop.
Save ingozoell/7294202 to your computer and use it in GitHub Desktop.
.evening {background: #999;}
/* ... */
<script type="text/javascript">
$(document).ready(function () {
datetoday = new Date(); // create new Date()
timenow = datetoday.getTime(); // grabbing the time it is now
datetoday.setTime(timenow); // setting the time now to datetoday variable
hournow = datetoday.getHours(); //the hour it is
if (hournow >= 18) // if it is after 6pm
$('body').addClass('evening');
else if (hournow >= 12) // if it is after 12pm
$('body').addClass('afternoon');
else if (hournow >= 6) // if it is after 6am
$('body').addClass('morning');
else if (hournow >= 0) // if it is after midnight
$('body').addClass('midnight');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment