admin管理员组

文章数量:1425995

If I do

function test()
    {
        var fromDate="01/17/2012";        
        var res= Test1(fromDate);
        return false;             
    }

 function Test1(d1) {


            alert(d1.getFullYear());           

        }

It is failing at d1.getFullYear() with the message

Microsoft JScript runtime error: Object doesn't support property or method 'getFullYear'

What is the problem..please help Thanks

If I do

function test()
    {
        var fromDate="01/17/2012";        
        var res= Test1(fromDate);
        return false;             
    }

 function Test1(d1) {


            alert(d1.getFullYear());           

        }

It is failing at d1.getFullYear() with the message

Microsoft JScript runtime error: Object doesn't support property or method 'getFullYear'

What is the problem..please help Thanks

Share Improve this question edited Jan 25, 2012 at 12:42 James Jithin 10.6k6 gold badges40 silver badges52 bronze badges asked Jan 25, 2012 at 12:37 user1025901user1025901 1,9094 gold badges22 silver badges28 bronze badges 2
  • fromDate is string not date object to support getFullYear function – Sudesh Commented Jan 25, 2012 at 12:39
  • When it's a Date object it works just fine - if this still fails it means the machine running this code has different regional settings, for example yyyy-mm-dd in which case correct string would be 2012-01-17. – user447356 Commented Jan 25, 2012 at 12:47
Add a ment  | 

1 Answer 1

Reset to default 4

The problem is that you have a string, and treat it likt it was a Date object.

Create a Date object:

var fromDate = new Date(2012, 0, 17);

or parse a string:

var fromDate = Date.parse('2012-01-17');

本文标签: internet explorer 9Javascript getFullYear function is not working in IE 9Stack Overflow