“JavaScript compare dos fechas” Código de respuesta

JavaScript compare dos fechas

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 las fechas en 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 la fecha y la hora en JS

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

Fecha de comparación en 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 fechas

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 dos fechas en JavaScript

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

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

Respuestas similares a “JavaScript compare dos fechas”

Preguntas similares a “JavaScript compare dos fechas”

Más respuestas relacionadas con “JavaScript compare dos fechas” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código