Reputation: 566
I want to compare two datetime of the same time zone in javascript.
I have tried below code but it's not working due to timezone. I can't get a real local timestamp with timezone.
var createdAt = "2019-07-28T18:14:46+05:30";
var NowTime = new Date($.now());
if(createdAt < NowTime){
$("#sos1").css("background-color","#093");
}else{
$("#sos1").css("background-color","#F03");
}
Upvotes: 0
Views: 130
Reputation: 3782
Convert the datestring to date first using new Date()
function
var createdAt = new Date("2019-07-28T18:14:46+05:30");
var NowTime = new Date();
if(createdAt < NowTime){
alert(1);
}else{
alert(2);
}
Upvotes: 1