Compare angular data Js

0

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?

    
asked by anonymous 14.10.2017 / 16:45

1 answer

1

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.

    
02.07.2018 / 03:34