0

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");
}
Ratan Uday Kumar
  • 5,738
  • 6
  • 35
  • 54
mageDev0688
  • 566
  • 4
  • 27

1 Answers1

1

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);
}
Vineesh
  • 3,762
  • 20
  • 37
  • Is this will work exact, because data will be fetch each 30 seconds. And every seconds data will change dynamically. – mageDev0688 Jul 29 '19 at 03:34