“Bandingkan Dua Tanggal String JavaScript” Kode Jawaban

Bandingkan tanggal di JS

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

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

Jawaban yang mirip dengan “Bandingkan Dua Tanggal String JavaScript”

Pertanyaan yang mirip dengan “Bandingkan Dua Tanggal String JavaScript”

Lebih banyak jawaban terkait untuk “Bandingkan Dua Tanggal String JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya