Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE8: Object Doesn't Support This Property or Method (Date function)

I'm getting an error that only appears on the great IE8, it points to the following function, specifically the line: return (expDate.getTime() > Date.now());

$.validator.addMethod("checkDocExpiry",function(value) {
    var driverLicExp = ($('#drivers-license-expiration').val()) ? $('#drivers-license-expiration').val() : '';
    if (driverLicExp != ''){
        var expDate = new Date(driverLicExp);
        return (expDate.getTime() > Date.now());
    }else{
        return (true);
    }
}, "Your driver's license has expired.");

I'm not sure what would cause this, I am fairly new to developing for older browsers. This runs fine in FF, IE10, Chrome, Safari.

Any help would be much appreciated.

Thanks

like image 789
Neil Avatar asked Aug 05 '13 22:08

Neil


2 Answers

Looks like Date.now() isn't supported in IE8 (see the table at the bottom):

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now

new Date() should get you a date object with the current date.

like image 168
Jason P Avatar answered Nov 09 '22 13:11

Jason P


Shim using the fact valueOf a Date is ms..

if (!Date.now) Date.now = function () {return +new Date();};
like image 45
Paul S. Avatar answered Nov 09 '22 12:11

Paul S.