最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - IE8: Object Doesn't Support This Property or Method (Date function) - Stack Overflow

programmeradmin2浏览0评论

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

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

Share Improve this question asked Aug 5, 2013 at 22:00 NeilNeil 2,5197 gold badges34 silver badges47 bronze badges 2
  • It is a date from the jquery UI date picker. In this specific test case: 08/13/2013 – Neil Commented Aug 5, 2013 at 22:04
  • —not your immediate issue, but you should not rely on the Date object to parse random strings as dates, particularly dates as regionally specific as the one in your comment. – RobG Commented Aug 5, 2013 at 23:38
Add a comment  | 

4 Answers 4

Reset to default 10

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.

Shim using the fact valueOf a Date is ms..

if (!Date.now) Date.now = function () {return +new Date();};

IE 8 does not support Date.now. Implement it as :

if(!Date.now) { Date.now = function(){ return new Date().getTime();};}

My psychic debugging skills tell me that you're using jQuery 2.0, which does not support IE8.

You need to use 1.10.

发布评论

评论列表(0)

  1. 暂无评论