Javascript

Check If A Date Is More Than 1 Hour Ago

Posted by Weston Ganger on June 16, 2016

Javascript can be a bit difficult to work with time without a library but heres two simple ways to check a date.

This example shows checking if myDate is more than an hour from the current time.


var oneHour = 60 * 60 * 1000;
if((new(Date) - myDate) > oneHour){
  // do work
}

Another example is to get the time one hour from the current time.


var oneHour = 60 * 60 * 1000;
new Date(new(Date) + oneHour);


Related External Links:


Posted in Javascript and Tagged with date time 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts