Skip to content

Instantly share code, notes, and snippets.

@ryanemitchell
Last active September 27, 2017 20:48
Show Gist options
  • Save ryanemitchell/4a729d9302be7ba6f6a4cd2d00b5ad71 to your computer and use it in GitHub Desktop.
Save ryanemitchell/4a729d9302be7ba6f6a4cd2d00b5ad71 to your computer and use it in GitHub Desktop.
Get current hout and minutes and output based on 2 times (open and closed) Use moment.js when need more functionaality than this.
var d = new Date();
var hr = d.getHours();
var min = d.getMinutes();
// combine hours and minutes and convert string to number
var currenttime = parseFloat(""+ hr+min);
//set open and close times
var opentime = 830;
var closetime = 2044;
if (currenttime > opentime && currenttime < closetime) {
//open
console.log(currenttime +'\ '+'open');
document.write('<span style=\"color:#eaea23\">OPEN</span>');
} else {
//closed
console.log(currenttime +'\ '+'closed');
document.write('<span style=\"color:#eaea23\">Closed</span>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment