Date () function {{native code]} doesn't use compareTo when using Date.js in Chrome

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 use ( http://code.google.com/p/datejs/wiki/APIDocumentation#compareTo )

 return first_date.compareTo(second_date) 

an exception occurs:

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

I am using the latest version of Date.js from http://www.datejs.com/

How to solve this problem?

I mentioned that other functions (add (-5) .days (), today (), etc.) work fine.

PS: I looked here ( http://code.google.com/p/datejs/issues/detail?id=129 ), but not a workaround.

+4
source share
2 answers

first_date and second_date are strings according to your code, and Date.compare doesn't even exist unless you use the svn-trunk version .

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

+5
source
 first_date = Date.parse('05/21/2012 0:00:00 '); second_date = Date.today(); console.log(first_date.compareTo(second_date)); // just working fine 
+1
source

Source: https://habr.com/ru/post/1414305/


All Articles