“JavaScript Compare duas datas” Respostas de código

JavaScript Compare duas datas

var date1 = new Date('December 25, 2017 01:30:00');
var date2 = new Date('June 18, 2016 02:30:00');

//best to use .getTime() to compare dates
if(date1.getTime() === date2.getTime()){
    //same date
}

if(date1.getTime() > date2.getTime()){
    //date 1 is newer
}
Grepper

Compare datas em JavaScript

var date1 = new Date('December 25, 2017 01:30:00');
var date2 = new Date('June 18, 2016 02:30:00');

//best to use .getTime() to compare dates
if(date1.getTime() === date2.getTime()){
    //same date
}

if(date1.getTime() > date2.getTime()){
    //date 1 is newer
}
Jealous Jackal

Compare data e hora em JS

var isLarger = new Date("2-11-2012 13:40:00") > new Date("01-11-2012 10:40:00");
Clumsy Cicada

Data Compare em JS

var x = new Date('2013-05-23');
var y = new Date('2013-05-23');

// less than, greater than is fine:
x < y; => false
x > y; => false
x === y; => false, oops!

// anything involving '=' should use the '+' prefix
// it will then compare the dates' millisecond values
+x <= +y;  => true
+x >= +y;  => true
+x === +y; => true
Impossible Iguana

JavaScript Compare datas

let myDate = new Date("January 13, 2021 12:00:00");
let yourDate = new Date("January 13, 2021 15:00:00");

if (myDate < yourDate) {
  console.log("myDate is less than yourDate"); // will be printed
}
if (myDate > yourDate) {
  console.log("myDate is greater than yourDate");
}
Scary Sardine

Compare duas datas em JavaScript

a = new Date(1995,11,17);
b = new Date(1995,11,17);

a.getTime() === b.getTime() // prints true
Awful Aardvark

Respostas semelhantes a “JavaScript Compare duas datas”

Perguntas semelhantes a “JavaScript Compare duas datas”

Mais respostas relacionadas para “JavaScript Compare duas datas” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código