I would like to compare two dates in angular js, the two dates are like this:
Sat Oct 14 2017 11:43:46 GMT-0300 (Hora oficial do Brasil)
Sat Oct 14 2017 17:53:51 GMT-0300 (Hora oficial do Brasil)
How do I get these two dates?
I would like to compare two dates in angular js, the two dates are like this:
Sat Oct 14 2017 11:43:46 GMT-0300 (Hora oficial do Brasil)
Sat Oct 14 2017 17:53:51 GMT-0300 (Hora oficial do Brasil)
How do I get these two dates?
Comparing dates can be done using pure JavaScript through Date class objects.
const data1 = new Date('Sat Oct 14 2017 11:43:46 GMT-0300 (Hora oficial do Brasil)');
const data2 = new Date('Sat Oct 14 2017 17:53:51 GMT-0300 (Hora oficial do Brasil)');
const datasIguais = data1.getTime() === data2.getTime(); -- false
const datasDiferentes = data1.getTime() !== data2.getTime(); -- true
const primeiraDataAnteriorSegunda = data1.getTime() < data2.getTime(); -- true
const primeiraDataPosteriorSegunda = data1.getTime() > data2.getTime(); -- false
Note that you should always make the comparison from the return of the date class's getTime () method that returns the time value that is the number of milliseconds since January 1, 1970 (UTC). Do not make comparisons directly between variables , as they are just references to instantiated objects.