admin管理员组

文章数量:1326118

I have these two date time variables in javascript:

first_date = Date.parse('05/21/2012 0:00:00 ');
second_date = Date.today();

If I'm using ( )

return first_datepareTo(second_date)

then exception occurs:

Object function Date() { [native code] } has no method 'pareTo' in Google Chrome.

I'm using latest version of Date.js from /

How to solve this issue ?

I will mention that other functions (add(-5).days(), today(), etc.) works fine.

PS: I took a look here ( ) but no workaround.

I have these two date time variables in javascript:

first_date = Date.parse('05/21/2012 0:00:00 ');
second_date = Date.today();

If I'm using ( http://code.google./p/datejs/wiki/APIDocumentation#pareTo )

return first_date.pareTo(second_date)

then exception occurs:

Object function Date() { [native code] } has no method 'pareTo' in Google Chrome.

I'm using latest version of Date.js from http://www.datejs./

How to solve this issue ?

I will mention that other functions (add(-5).days(), today(), etc.) works fine.

PS: I took a look here ( http://code.google./p/datejs/issues/detail?id=129 ) but no workaround.

Share Improve this question edited May 25, 2012 at 6:32 Snake Eyes asked May 25, 2012 at 6:15 Snake EyesSnake Eyes 16.8k39 gold badges118 silver badges232 bronze badges 1
  • first_date isn't a Date, it's a string, so that would explain why it doesn't have a pareTo method. You mention Chrome several times - does that imply your code does work in other browsers, or that you haven't tested in other browsers? The latest version of date.js that I downloaded didn't seem to define a pare method, just pareTo. – nnnnnn Commented May 25, 2012 at 6:20
Add a ment  | 

2 Answers 2

Reset to default 5

first_date and second_date are strings according to your code and Date.pare does not even exist unless you are using the svn-trunk version.

datejs defines Date.prototype.pareTo so you can only use date_obj_a.pareTo(...).

first_date = Date.parse('05/21/2012 0:00:00 ');
second_date = Date.today();

console.log(first_date.pareTo(second_date)); // just working fine

本文标签: