开发者

Cannot find function getMonth in Object 05/06/11

Why do i get this error, when i format my date? Code follows below

var date = /Date(1306348200000)/

function dateToString(date) {
    return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getYear();
}

function dateFromString(开发者_运维问答str) {
    return new Date(str);
}


You define var date as a regular which can not be accepted by new Date,just do it like this.

var date = 1312711261103;

try it like this: http://jsfiddle.net/zhiyelee/wLNSS/


In your code, date is a regular expression, not a Date object. You probably want:

var date = new Date(1306348200000);

Also note that calling date Date without new returns a string and not a Date object.

Edit: Apparently I overlooked the dateFromString function, but your code does not show what you do with date and how you use these functions. Anyway, it should be clear which value you have to pass to Date. Definitely not a regular expression.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜