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 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts