Im working on a website, and between the hours of 9:00 and 24:00, the business is open. During those hours, i want a line of text to say "Store is currently open" but during 0:00 - 8:59, i want the line of text to say "Store is closed".
            Asked
            
        
        
            Active
            
        
            Viewed 29 times
        
    -4
            
            
        - 
                    Between 0900 and 2400 where? Where you are? Where your server is? Where your customer is? All of the above? None of the above? – Jan 20 '15 at 01:33
- 
                    possible duplicate of [Comparing Time using Javascript](http://stackoverflow.com/questions/4406505/comparing-time-using-javascript) – Myles Baker Jan 20 '15 at 01:34
1 Answers
0
            
            
        Simply use Moment.js. If you're only targetting local users you don't even have to worry about time-zone differences. Otherwise you can always specify a timezone to use, simply see the docs.
var now = moment();
var status = (now.isAfter(moment('09:00', 'hh:mm')) && now.isBefore(moment('21:00', 'hh:mm'))) ? 'open' : 'closed';
var d = document.createElement("span");
d.appendChild(document.createTextNode("the time is now " + moment().format('hh:mm') + ". pool's " + status + "."));
document.body.appendChild(d);<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script> 
    
    
        Etheryte
        
- 24,589
- 11
- 71
- 116
