“JavaScript Bandingkan dua tanggal” Kode Jawaban

JavaScript Bandingkan dua tanggal

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

Bandingkan tanggal dalam 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

Bandingkan tanggal dan waktu di JS

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

Tanggal Bandingkan di 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 Bandingkan Tanggal

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

Bandingkan dua tanggal dalam JavaScript

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

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

Jawaban yang mirip dengan “JavaScript Bandingkan dua tanggal”

Pertanyaan yang mirip dengan “JavaScript Bandingkan dua tanggal”

Lebih banyak jawaban terkait untuk “JavaScript Bandingkan dua tanggal” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya