“JavaScript compare deux dates” Réponses codées

JavaScript compare deux dates

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

Comparez les dates 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

Comparez la date et l'heure à JS

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

Date de comparaison dans 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 comparer les dates

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

Comparez deux dates en javascript

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

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

Réponses similaires à “JavaScript compare deux dates”

Questions similaires à “JavaScript compare deux dates”

Plus de réponses similaires à “JavaScript compare deux dates” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code